openai-sdk-helpers 0.6.1__py3-none-any.whl → 0.6.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ from .validator import ValidatorAgent
14
14
  from .utils import run_coroutine_agent_sync
15
15
  from .search.vector import VectorAgentSearch
16
16
  from .search.web import WebAgentSearch
17
+ from .files import build_agent_input_messages
17
18
 
18
19
  __all__ = [
19
20
  "AgentBase",
@@ -34,4 +35,5 @@ __all__ = [
34
35
  "ValidatorAgent",
35
36
  "VectorAgentSearch",
36
37
  "WebAgentSearch",
38
+ "build_agent_input_messages",
37
39
  ]
@@ -6,7 +6,7 @@ import logging
6
6
  import traceback
7
7
  import uuid
8
8
  from pathlib import Path
9
- from typing import TYPE_CHECKING, Any, Dict, Optional, Protocol, cast
9
+ from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Protocol, cast
10
10
 
11
11
  from agents import Agent, Handoff, InputGuardrail, OutputGuardrail, Session
12
12
  from agents.model_settings import ModelSettings
@@ -33,6 +33,7 @@ from .runner import run_async, run_sync
33
33
  if TYPE_CHECKING:
34
34
  from ..settings import OpenAISettings
35
35
  from ..response.base import ResponseBase
36
+ from ..files_api import FilePurpose, FilesAPIManager
36
37
 
37
38
 
38
39
  class AgentConfigurationProtocol(Protocol):
@@ -184,6 +185,8 @@ class AgentBase(DataclassJSONSerializable):
184
185
  Return response tool handler and definition for Responses API use.
185
186
  build_response(openai_settings, data_path=None, tool_handlers=None, system_vector_store=None)
186
187
  Build a ResponseBase instance based on this agent.
188
+ build_input_messages(content, files=None, files_manager=None, file_purpose="user_data", image_detail="auto")
189
+ Build Agents SDK input messages with optional file attachments.
187
190
  save_error(exc)
188
191
  Persist error details to a file named with the agent UUID.
189
192
  close()
@@ -467,7 +470,7 @@ class AgentBase(DataclassJSONSerializable):
467
470
 
468
471
  async def run_async(
469
472
  self,
470
- input: str,
473
+ input: str | list[dict[str, Any]],
471
474
  *,
472
475
  context: Optional[Dict[str, Any]] = None,
473
476
  output_structure: Optional[type[StructureBase]] = None,
@@ -477,8 +480,8 @@ class AgentBase(DataclassJSONSerializable):
477
480
 
478
481
  Parameters
479
482
  ----------
480
- input : str
481
- Prompt or query for the agent.
483
+ input : str or list[dict[str, Any]]
484
+ Prompt text or structured input for the agent.
482
485
  context : dict or None, default=None
483
486
  Optional dictionary passed to the agent.
484
487
  output_structure : type[StructureBase] or None, default=None
@@ -522,7 +525,7 @@ class AgentBase(DataclassJSONSerializable):
522
525
 
523
526
  def run_sync(
524
527
  self,
525
- input: str,
528
+ input: str | list[dict[str, Any]],
526
529
  *,
527
530
  context: Optional[Dict[str, Any]] = None,
528
531
  output_structure: Optional[type[StructureBase]] = None,
@@ -532,8 +535,8 @@ class AgentBase(DataclassJSONSerializable):
532
535
 
533
536
  Parameters
534
537
  ----------
535
- input : str
536
- Prompt or query for the agent.
538
+ input : str or list[dict[str, Any]]
539
+ Prompt text or structured input for the agent.
537
540
  context : dict or None, default=None
538
541
  Optional dictionary passed to the agent.
539
542
  output_structure : type[StructureBase] or None, default=None
@@ -660,6 +663,71 @@ class AgentBase(DataclassJSONSerializable):
660
663
  openai_settings=openai_settings,
661
664
  )
662
665
 
666
+ @staticmethod
667
+ def build_input_messages(
668
+ content: str | list[str],
669
+ files: str | list[str] | None = None,
670
+ *,
671
+ files_manager: FilesAPIManager | None = None,
672
+ openai_settings: OpenAISettings | None = None,
673
+ file_purpose: FilePurpose = "user_data",
674
+ image_detail: Literal["low", "high", "auto"] = "auto",
675
+ ) -> list[dict[str, Any]]:
676
+ """Build Agents SDK input messages with file attachments.
677
+
678
+ Parameters
679
+ ----------
680
+ content : str or list[str]
681
+ Prompt text or list of prompt texts to send.
682
+ files : str, list[str], or None, default None
683
+ Optional file path or list of file paths. Image files are sent as
684
+ base64-encoded ``input_image`` entries. Document files are uploaded
685
+ using ``files_manager`` and sent as ``input_file`` entries.
686
+ files_manager : FilesAPIManager or None, default None
687
+ File upload helper used to create file IDs for document uploads.
688
+ Required when ``files`` contains non-image documents.
689
+ openai_settings : OpenAISettings or None, default None
690
+ Optional OpenAI settings used to build a FilesAPIManager when one is
691
+ not provided. When supplied, ``openai_settings.create_client()`` is
692
+ used to initialize the Files API manager.
693
+ file_purpose : FilePurpose, default "user_data"
694
+ Purpose passed to the Files API when uploading document files.
695
+ image_detail : {"low", "high", "auto"}, default "auto"
696
+ Detail hint passed along with base64-encoded image inputs.
697
+
698
+ Returns
699
+ -------
700
+ list[dict[str, Any]]
701
+ Agents SDK input messages that include text and optional file entries.
702
+
703
+ Raises
704
+ ------
705
+ ValueError
706
+ If document files are provided without a ``files_manager``.
707
+
708
+ Examples
709
+ --------
710
+ >>> from openai import OpenAI
711
+ >>> from openai_sdk_helpers.files_api import FilesAPIManager
712
+ >>> client = OpenAI()
713
+ >>> files_manager = FilesAPIManager(client)
714
+ >>> messages = AgentBase.build_input_messages(
715
+ ... "Summarize this document",
716
+ ... files="report.pdf",
717
+ ... files_manager=files_manager,
718
+ ... )
719
+ """
720
+ from .files import build_agent_input_messages
721
+
722
+ return build_agent_input_messages(
723
+ content=content,
724
+ files=files,
725
+ files_manager=files_manager,
726
+ openai_settings=openai_settings,
727
+ file_purpose=file_purpose,
728
+ image_detail=image_detail,
729
+ )
730
+
663
731
  def _build_response_parameters(self) -> dict[str, Any]:
664
732
  """Build the Responses API parameter schema for this agent tool.
665
733