openai-sdk-helpers 0.4.2__py3-none-any.whl → 0.5.0__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.
Files changed (68) hide show
  1. openai_sdk_helpers/__init__.py +45 -41
  2. openai_sdk_helpers/agent/__init__.py +4 -6
  3. openai_sdk_helpers/agent/base.py +110 -191
  4. openai_sdk_helpers/agent/{config.py → configuration.py} +24 -32
  5. openai_sdk_helpers/agent/{coordination.py → coordinator.py} +22 -23
  6. openai_sdk_helpers/agent/runner.py +3 -45
  7. openai_sdk_helpers/agent/search/base.py +54 -76
  8. openai_sdk_helpers/agent/search/vector.py +92 -108
  9. openai_sdk_helpers/agent/search/web.py +104 -82
  10. openai_sdk_helpers/agent/summarizer.py +22 -28
  11. openai_sdk_helpers/agent/translator.py +22 -24
  12. openai_sdk_helpers/agent/{validation.py → validator.py} +19 -23
  13. openai_sdk_helpers/cli.py +8 -22
  14. openai_sdk_helpers/environment.py +8 -13
  15. openai_sdk_helpers/errors.py +9 -0
  16. openai_sdk_helpers/extract/__init__.py +23 -0
  17. openai_sdk_helpers/extract/extractor.py +157 -0
  18. openai_sdk_helpers/extract/generator.py +476 -0
  19. openai_sdk_helpers/prompt/extractor_config_agent_instructions.jinja +6 -0
  20. openai_sdk_helpers/prompt/extractor_config_generator.jinja +37 -0
  21. openai_sdk_helpers/prompt/extractor_config_generator_instructions.jinja +9 -0
  22. openai_sdk_helpers/prompt/extractor_prompt_optimizer_agent_instructions.jinja +4 -0
  23. openai_sdk_helpers/prompt/extractor_prompt_optimizer_request.jinja +11 -0
  24. openai_sdk_helpers/prompt/vector_planner.jinja +7 -0
  25. openai_sdk_helpers/prompt/vector_search.jinja +6 -0
  26. openai_sdk_helpers/prompt/vector_writer.jinja +7 -0
  27. openai_sdk_helpers/response/__init__.py +3 -7
  28. openai_sdk_helpers/response/base.py +89 -98
  29. openai_sdk_helpers/response/{config.py → configuration.py} +45 -20
  30. openai_sdk_helpers/response/files.py +2 -0
  31. openai_sdk_helpers/response/planner.py +1 -1
  32. openai_sdk_helpers/response/prompter.py +1 -1
  33. openai_sdk_helpers/response/runner.py +1 -48
  34. openai_sdk_helpers/response/tool_call.py +0 -141
  35. openai_sdk_helpers/response/vector_store.py +8 -5
  36. openai_sdk_helpers/streamlit_app/__init__.py +1 -1
  37. openai_sdk_helpers/streamlit_app/app.py +17 -18
  38. openai_sdk_helpers/streamlit_app/{config.py → configuration.py} +13 -13
  39. openai_sdk_helpers/structure/__init__.py +16 -0
  40. openai_sdk_helpers/structure/base.py +239 -278
  41. openai_sdk_helpers/structure/extraction.py +1228 -0
  42. openai_sdk_helpers/structure/plan/plan.py +0 -20
  43. openai_sdk_helpers/structure/plan/task.py +0 -33
  44. openai_sdk_helpers/structure/prompt.py +16 -0
  45. openai_sdk_helpers/structure/responses.py +2 -2
  46. openai_sdk_helpers/structure/web_search.py +0 -10
  47. openai_sdk_helpers/tools.py +346 -99
  48. openai_sdk_helpers/types.py +3 -3
  49. openai_sdk_helpers/utils/__init__.py +9 -6
  50. openai_sdk_helpers/utils/json/base_model.py +316 -33
  51. openai_sdk_helpers/utils/json/data_class.py +1 -1
  52. openai_sdk_helpers/utils/langextract.py +194 -0
  53. openai_sdk_helpers/utils/registry.py +19 -15
  54. openai_sdk_helpers/vector_storage/storage.py +1 -1
  55. {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/METADATA +25 -11
  56. openai_sdk_helpers-0.5.0.dist-info/RECORD +95 -0
  57. openai_sdk_helpers/agent/prompt_utils.py +0 -15
  58. openai_sdk_helpers/context_manager.py +0 -241
  59. openai_sdk_helpers/deprecation.py +0 -167
  60. openai_sdk_helpers/retry.py +0 -175
  61. openai_sdk_helpers/streamlit_app/streamlit_web_search.py +0 -75
  62. openai_sdk_helpers/utils/deprecation.py +0 -167
  63. openai_sdk_helpers-0.4.2.dist-info/RECORD +0 -88
  64. /openai_sdk_helpers/{logging_config.py → logging.py} +0 -0
  65. /openai_sdk_helpers/{config.py → settings.py} +0 -0
  66. {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/WHEEL +0 -0
  67. {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/entry_points.txt +0 -0
  68. {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/licenses/LICENSE +0 -0
@@ -11,11 +11,10 @@ from pathlib import Path
11
11
  from typing import Any, Callable, Dict, List, Optional
12
12
 
13
13
 
14
- from ..structure import TaskStructure, PlanStructure, PromptStructure
15
- from ..utils import DataclassJSONSerializable, ensure_directory, log
14
+ from ..structure import TaskStructure, PlanStructure, PromptStructure, AgentEnum
15
+ from ..utils import ensure_directory, log
16
16
  from .base import AgentBase
17
- from .config import AgentConfiguration
18
- from ..structure.plan.enum import AgentEnum
17
+ from .configuration import AgentConfiguration
19
18
 
20
19
  PromptFn = Callable[[str], PromptStructure]
21
20
  BuildPlanFn = Callable[[str], PlanStructure]
@@ -40,12 +39,12 @@ class CoordinatorAgent(AgentBase):
40
39
  Base path for persisting project artifacts.
41
40
  name : str
42
41
  Name of the parent module for data organization.
43
- config : AgentConfiguration or None, default=None
42
+ configuration : AgentConfiguration or None, default=None
44
43
  Optional agent configuration describing prompts and metadata.
45
- prompt_dir : Path or None, default=None
46
- Optional directory holding prompt templates.
47
- default_model : str or None, default=None
48
- Optional fallback model identifier.
44
+ template_path : Path or None, default=None
45
+ Optional template file path for prompt rendering.
46
+ model : str or None, default=None
47
+ Model identifier to use for coordinator operations.
49
48
 
50
49
  Methods
51
50
  -------
@@ -84,9 +83,9 @@ class CoordinatorAgent(AgentBase):
84
83
  summarize_fn: SummarizeFn,
85
84
  module_data_path: Path,
86
85
  name: str,
87
- config: Optional[AgentConfiguration] = None,
88
- prompt_dir: Optional[Path] = None,
89
- default_model: Optional[str] = None,
86
+ configuration: Optional[AgentConfiguration] = None,
87
+ template_path: Optional[Path] = None,
88
+ model: Optional[str] = None,
90
89
  ) -> None:
91
90
  """Initialize the project manager with injected workflow helpers.
92
91
 
@@ -104,12 +103,12 @@ class CoordinatorAgent(AgentBase):
104
103
  Base path for persisting project artifacts.
105
104
  name : str
106
105
  Name of the parent module for data organization.
107
- config : AgentConfiguration or None, default=None
106
+ configuration : AgentConfiguration or None, default=None
108
107
  Optional agent configuration describing prompts and metadata.
109
- prompt_dir : Path or None, default=None
110
- Optional directory holding prompt templates.
111
- default_model : str or None, default=None
112
- Optional fallback model identifier.
108
+ template_path : Path or None, default=None
109
+ Optional template file path for prompt rendering.
110
+ model : str or None, default=None
111
+ Model identifier to use for coordinator operations.
113
112
 
114
113
  Raises
115
114
  ------
@@ -127,15 +126,15 @@ class CoordinatorAgent(AgentBase):
127
126
  ... name="test",
128
127
  ... )
129
128
  """
130
- if config is None:
131
- config = AgentConfiguration(
132
- name="coordinator_agent",
129
+ if configuration is None:
130
+ configuration = AgentConfiguration(
131
+ name=__class__.__name__,
133
132
  instructions="Coordinate agents for planning and summarization.",
134
133
  description="Coordinates agents for planning and summarization.",
134
+ template_path=template_path,
135
+ model=model,
135
136
  )
136
- super().__init__(
137
- config=config, prompt_dir=prompt_dir, default_model=default_model
138
- )
137
+ super().__init__(configuration=configuration)
139
138
  self._prompt_fn = prompt_fn
140
139
  self._build_plan_fn = build_plan_fn
141
140
  self._execute_plan_fn = execute_plan_fn
@@ -2,14 +2,14 @@
2
2
 
3
3
  These helpers provide a consistent interface around the lower-level functions in
4
4
  the ``agent.base`` module, allowing callers to execute agents with consistent
5
- signatures whether they need asynchronous, synchronous, or streamed results.
5
+ signatures whether they need asynchronous or synchronous results.
6
6
  """
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
10
  from typing import Any, Dict, Optional
11
11
 
12
- from agents import Agent, RunResult, RunResultStreaming, Runner, Session
12
+ from agents import Agent, RunResult, Runner, Session
13
13
 
14
14
  from openai_sdk_helpers.utils.async_utils import run_coroutine_with_fallback
15
15
  from ..structure.base import StructureBase
@@ -109,46 +109,4 @@ def run_sync(
109
109
  return result
110
110
 
111
111
 
112
- def run_streamed(
113
- agent: Agent,
114
- input: str,
115
- *,
116
- context: Optional[Dict[str, Any]] = None,
117
- output_structure: Optional[type[StructureBase]] = None,
118
- session: Optional[Session] = None,
119
- ) -> RunResultStreaming | StructureBase:
120
- """Stream agent execution results.
121
-
122
- Parameters
123
- ----------
124
- agent : Agent
125
- Configured agent to execute.
126
- input : str
127
- Prompt or query string for the agent.
128
- context : dict or None, default=None
129
- Optional context dictionary passed to the agent.
130
- output_structure : type[StructureBase] or None, default=None
131
- Optional type used to cast the final output.
132
- session : Session or None, default=None
133
- Optional session for maintaining conversation history.
134
-
135
- Returns
136
- -------
137
- RunResultStreaming
138
- Streaming output wrapper from the agent execution.
139
-
140
- Examples
141
- --------
142
- >>> from agents import Agent
143
- >>> agent = Agent(name="test", instructions="test", model="gpt-4o-mini")
144
- >>> result = run_streamed(agent, "Explain AI") # doctest: +SKIP
145
- >>> for chunk in result.stream_text(): # doctest: +SKIP
146
- ... print(chunk, end="")
147
- """
148
- result = Runner.run_streamed(agent, input, context=context, session=session)
149
- if output_structure is not None:
150
- return result.final_output_as(output_structure)
151
- return result
152
-
153
-
154
- __all__ = ["run_sync", "run_async", "run_streamed"]
112
+ __all__ = ["run_sync", "run_async"]
@@ -10,10 +10,10 @@ from __future__ import annotations
10
10
  import asyncio
11
11
  from abc import ABC, abstractmethod
12
12
  from pathlib import Path
13
- from typing import Generic, List, Optional, TypeVar, Union
13
+ from typing import Any, Generic, List, Optional, TypeVar, Union
14
14
 
15
15
  from ..base import AgentBase
16
- from ..config import AgentConfiguration
16
+ from ..configuration import AgentConfiguration
17
17
  from ...structure.base import StructureBase
18
18
 
19
19
  # Type variables for search workflow components
@@ -33,10 +33,10 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
33
33
 
34
34
  Parameters
35
35
  ----------
36
- prompt_dir : Path, optional
37
- Directory containing prompt templates.
38
- default_model : str, optional
39
- Default model identifier to use when not defined in config.
36
+ template_path : Path | str | None, optional
37
+ Template file path for prompt rendering.
38
+ model : str | None, optional
39
+ Model identifier to use when not defined in configuration.
40
40
 
41
41
  Methods
42
42
  -------
@@ -48,35 +48,39 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
48
48
  Raises
49
49
  ------
50
50
  ValueError
51
- If the default model is not provided.
51
+ If the configuration omits a model identifier.
52
52
 
53
53
  Examples
54
54
  --------
55
55
  >>> class MyPlanner(SearchPlanner):
56
- ... def _configure_agent(self):
56
+ ... def _configure_agent(self, template_path=None, model=None):
57
57
  ... return AgentConfiguration(
58
58
  ... name="my_planner",
59
59
  ... description="Plans searches",
60
60
  ... output_structure=WebSearchPlanStructure,
61
61
  ... )
62
- >>> planner = MyPlanner(default_model="gpt-4o-mini")
62
+ >>> planner = MyPlanner(model="gpt-4o-mini")
63
63
  """
64
64
 
65
65
  def __init__(
66
66
  self,
67
- prompt_dir: Optional[Path] = None,
68
- default_model: Optional[str] = None,
67
+ template_path: Path | str | None = None,
68
+ model: str | None = None,
69
+ **kwargs: Any,
69
70
  ) -> None:
70
71
  """Initialize the planner agent."""
71
- config = self._configure_agent()
72
- super().__init__(
73
- config=config,
74
- prompt_dir=prompt_dir,
75
- default_model=default_model,
72
+ configuration = self._configure_agent(
73
+ template_path=template_path, model=model, **kwargs
76
74
  )
75
+ super().__init__(configuration=configuration)
77
76
 
78
77
  @abstractmethod
79
- def _configure_agent(self) -> AgentConfiguration:
78
+ def _configure_agent(
79
+ self,
80
+ template_path: Path | str | None = None,
81
+ model: str | None = None,
82
+ **kwargs: Any,
83
+ ) -> AgentConfiguration:
80
84
  """Return configuration for this planner.
81
85
 
82
86
  Returns
@@ -86,12 +90,12 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
86
90
 
87
91
  Examples
88
92
  --------
89
- >>> config = AgentConfiguration(
93
+ >>> configuration = AgentConfiguration(
90
94
  ... name="web_planner",
91
95
  ... description="Plan web searches",
92
96
  ... output_structure=WebSearchPlanStructure,
93
97
  ... )
94
- >>> return config
98
+ >>> return configuration
95
99
  """
96
100
  pass
97
101
 
@@ -124,10 +128,10 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
124
128
 
125
129
  Parameters
126
130
  ----------
127
- prompt_dir : Path, optional
128
- Directory containing prompt templates.
129
- default_model : str, optional
130
- Default model identifier to use when not defined in config.
131
+ template_path : Path | str | None, optional
132
+ Template file path for prompt rendering.
133
+ model : str | None, optional
134
+ Model identifier to use when not defined in configuration.
131
135
  max_concurrent_searches : int, default=10
132
136
  Maximum number of concurrent search operations.
133
137
 
@@ -143,12 +147,12 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
143
147
  Raises
144
148
  ------
145
149
  ValueError
146
- If the default model is not provided.
150
+ If the configuration omits a model identifier.
147
151
 
148
152
  Examples
149
153
  --------
150
154
  >>> class MyTool(SearchToolAgent):
151
- ... def _configure_agent(self):
155
+ ... def _configure_agent(self, *, template_path: Path | str | None = None, model: str | None = None):
152
156
  ... return AgentConfiguration(
153
157
  ... name="my_tool",
154
158
  ... description="Executes searches",
@@ -156,27 +160,34 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
156
160
  ... )
157
161
  ... async def run_search(self, item):
158
162
  ... return "result"
159
- >>> tool = MyTool(default_model="gpt-4o-mini")
163
+ >>> tool = MyTool(model="gpt-4o-mini")
160
164
  """
161
165
 
162
166
  def __init__(
163
167
  self,
164
168
  *,
165
- prompt_dir: Optional[Path] = None,
166
- default_model: Optional[str] = None,
169
+ template_path: Path | str | None = None,
170
+ model: str | None = None,
167
171
  max_concurrent_searches: int = 10,
172
+ **kwargs: Any,
168
173
  ) -> None:
169
174
  """Initialize the search tool agent."""
170
175
  self._max_concurrent_searches = max_concurrent_searches
171
- config = self._configure_agent()
172
- super().__init__(
173
- config=config,
174
- prompt_dir=prompt_dir,
175
- default_model=default_model,
176
+ configuration = self._configure_agent(
177
+ template_path=template_path,
178
+ model=model,
179
+ **kwargs,
176
180
  )
181
+ super().__init__(configuration=configuration)
177
182
 
178
183
  @abstractmethod
179
- def _configure_agent(self) -> AgentConfiguration:
184
+ def _configure_agent(
185
+ self,
186
+ *,
187
+ template_path: Path | str | None = None,
188
+ model: str | None = None,
189
+ **kwargs: Any,
190
+ ) -> AgentConfiguration:
180
191
  """Return configuration for this tool agent.
181
192
 
182
193
  Returns
@@ -186,13 +197,13 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
186
197
 
187
198
  Examples
188
199
  --------
189
- >>> config = AgentConfiguration(
200
+ >>> configuration = AgentConfiguration(
190
201
  ... name="web_search",
191
202
  ... description="Perform web searches",
192
203
  ... input_structure=WebSearchPlanStructure,
193
204
  ... tools=[WebSearchTool()],
194
205
  ... )
195
- >>> return config
206
+ >>> return configuration
196
207
  """
197
208
  pass
198
209
 
@@ -247,10 +258,10 @@ class SearchWriter(AgentBase, Generic[ReportType]):
247
258
 
248
259
  Parameters
249
260
  ----------
250
- prompt_dir : Path, optional
251
- Directory containing prompt templates.
252
- default_model : str, optional
253
- Default model identifier to use when not defined in config.
261
+ template_path : Path | str | None, optional
262
+ Template file path for prompt rendering.
263
+ model : str | None, optional
264
+ Model identifier to use when not defined in configuration.
254
265
 
255
266
  Methods
256
267
  -------
@@ -262,53 +273,20 @@ class SearchWriter(AgentBase, Generic[ReportType]):
262
273
  Raises
263
274
  ------
264
275
  ValueError
265
- If the default model is not provided.
276
+ If the configuration omits a model identifier.
266
277
 
267
278
  Examples
268
279
  --------
269
280
  >>> class MyWriter(SearchWriter):
270
- ... def _configure_agent(self):
281
+ ... def _configure_agent(self, template_path=None, model=None):
271
282
  ... return AgentConfiguration(
272
283
  ... name="my_writer",
273
284
  ... description="Writes reports",
274
285
  ... output_structure=WebSearchReportStructure,
275
286
  ... )
276
- >>> writer = MyWriter(default_model="gpt-4o-mini")
287
+ >>> writer = MyWriter(model="gpt-4o-mini")
277
288
  """
278
289
 
279
- def __init__(
280
- self,
281
- prompt_dir: Optional[Path] = None,
282
- default_model: Optional[str] = None,
283
- ) -> None:
284
- """Initialize the writer agent."""
285
- config = self._configure_agent()
286
- super().__init__(
287
- config=config,
288
- prompt_dir=prompt_dir,
289
- default_model=default_model,
290
- )
291
-
292
- @abstractmethod
293
- def _configure_agent(self) -> AgentConfiguration:
294
- """Return configuration for this writer.
295
-
296
- Returns
297
- -------
298
- AgentConfiguration
299
- Configuration with name, description, and output_structure set.
300
-
301
- Examples
302
- --------
303
- >>> config = AgentConfiguration(
304
- ... name="web_writer",
305
- ... description="Write web search report",
306
- ... output_structure=WebSearchReportStructure,
307
- ... )
308
- >>> return config
309
- """
310
- pass
311
-
312
290
  async def run_agent(
313
291
  self,
314
292
  query: str,