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.
- openai_sdk_helpers/__init__.py +45 -41
- openai_sdk_helpers/agent/__init__.py +4 -6
- openai_sdk_helpers/agent/base.py +110 -191
- openai_sdk_helpers/agent/{config.py → configuration.py} +24 -32
- openai_sdk_helpers/agent/{coordination.py → coordinator.py} +22 -23
- openai_sdk_helpers/agent/runner.py +3 -45
- openai_sdk_helpers/agent/search/base.py +54 -76
- openai_sdk_helpers/agent/search/vector.py +92 -108
- openai_sdk_helpers/agent/search/web.py +104 -82
- openai_sdk_helpers/agent/summarizer.py +22 -28
- openai_sdk_helpers/agent/translator.py +22 -24
- openai_sdk_helpers/agent/{validation.py → validator.py} +19 -23
- openai_sdk_helpers/cli.py +8 -22
- openai_sdk_helpers/environment.py +8 -13
- openai_sdk_helpers/errors.py +9 -0
- openai_sdk_helpers/extract/__init__.py +23 -0
- openai_sdk_helpers/extract/extractor.py +157 -0
- openai_sdk_helpers/extract/generator.py +476 -0
- openai_sdk_helpers/prompt/extractor_config_agent_instructions.jinja +6 -0
- openai_sdk_helpers/prompt/extractor_config_generator.jinja +37 -0
- openai_sdk_helpers/prompt/extractor_config_generator_instructions.jinja +9 -0
- openai_sdk_helpers/prompt/extractor_prompt_optimizer_agent_instructions.jinja +4 -0
- openai_sdk_helpers/prompt/extractor_prompt_optimizer_request.jinja +11 -0
- openai_sdk_helpers/prompt/vector_planner.jinja +7 -0
- openai_sdk_helpers/prompt/vector_search.jinja +6 -0
- openai_sdk_helpers/prompt/vector_writer.jinja +7 -0
- openai_sdk_helpers/response/__init__.py +3 -7
- openai_sdk_helpers/response/base.py +89 -98
- openai_sdk_helpers/response/{config.py → configuration.py} +45 -20
- openai_sdk_helpers/response/files.py +2 -0
- openai_sdk_helpers/response/planner.py +1 -1
- openai_sdk_helpers/response/prompter.py +1 -1
- openai_sdk_helpers/response/runner.py +1 -48
- openai_sdk_helpers/response/tool_call.py +0 -141
- openai_sdk_helpers/response/vector_store.py +8 -5
- openai_sdk_helpers/streamlit_app/__init__.py +1 -1
- openai_sdk_helpers/streamlit_app/app.py +17 -18
- openai_sdk_helpers/streamlit_app/{config.py → configuration.py} +13 -13
- openai_sdk_helpers/structure/__init__.py +16 -0
- openai_sdk_helpers/structure/base.py +239 -278
- openai_sdk_helpers/structure/extraction.py +1228 -0
- openai_sdk_helpers/structure/plan/plan.py +0 -20
- openai_sdk_helpers/structure/plan/task.py +0 -33
- openai_sdk_helpers/structure/prompt.py +16 -0
- openai_sdk_helpers/structure/responses.py +2 -2
- openai_sdk_helpers/structure/web_search.py +0 -10
- openai_sdk_helpers/tools.py +346 -99
- openai_sdk_helpers/types.py +3 -3
- openai_sdk_helpers/utils/__init__.py +9 -6
- openai_sdk_helpers/utils/json/base_model.py +316 -33
- openai_sdk_helpers/utils/json/data_class.py +1 -1
- openai_sdk_helpers/utils/langextract.py +194 -0
- openai_sdk_helpers/utils/registry.py +19 -15
- openai_sdk_helpers/vector_storage/storage.py +1 -1
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/METADATA +25 -11
- openai_sdk_helpers-0.5.0.dist-info/RECORD +95 -0
- openai_sdk_helpers/agent/prompt_utils.py +0 -15
- openai_sdk_helpers/context_manager.py +0 -241
- openai_sdk_helpers/deprecation.py +0 -167
- openai_sdk_helpers/retry.py +0 -175
- openai_sdk_helpers/streamlit_app/streamlit_web_search.py +0 -75
- openai_sdk_helpers/utils/deprecation.py +0 -167
- openai_sdk_helpers-0.4.2.dist-info/RECORD +0 -88
- /openai_sdk_helpers/{logging_config.py → logging.py} +0 -0
- /openai_sdk_helpers/{config.py → settings.py} +0 -0
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/WHEEL +0 -0
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.5.0.dist-info}/entry_points.txt +0 -0
- {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
|
|
14
|
+
from ..structure import TaskStructure, PlanStructure, PromptStructure, AgentEnum
|
|
15
|
+
from ..utils import ensure_directory, log
|
|
16
16
|
from .base import AgentBase
|
|
17
|
-
from .
|
|
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
|
-
|
|
42
|
+
configuration : AgentConfiguration or None, default=None
|
|
44
43
|
Optional agent configuration describing prompts and metadata.
|
|
45
|
-
|
|
46
|
-
Optional
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
106
|
+
configuration : AgentConfiguration or None, default=None
|
|
108
107
|
Optional agent configuration describing prompts and metadata.
|
|
109
|
-
|
|
110
|
-
Optional
|
|
111
|
-
|
|
112
|
-
|
|
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
|
|
131
|
-
|
|
132
|
-
name=
|
|
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
|
|
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,
|
|
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
|
-
|
|
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 ..
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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(
|
|
62
|
+
>>> planner = MyPlanner(model="gpt-4o-mini")
|
|
63
63
|
"""
|
|
64
64
|
|
|
65
65
|
def __init__(
|
|
66
66
|
self,
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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(
|
|
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
|
-
>>>
|
|
93
|
+
>>> configuration = AgentConfiguration(
|
|
90
94
|
... name="web_planner",
|
|
91
95
|
... description="Plan web searches",
|
|
92
96
|
... output_structure=WebSearchPlanStructure,
|
|
93
97
|
... )
|
|
94
|
-
>>> return
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
|
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(
|
|
163
|
+
>>> tool = MyTool(model="gpt-4o-mini")
|
|
160
164
|
"""
|
|
161
165
|
|
|
162
166
|
def __init__(
|
|
163
167
|
self,
|
|
164
168
|
*,
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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(
|
|
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
|
-
>>>
|
|
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
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
|
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(
|
|
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,
|