openai-sdk-helpers 0.4.2__py3-none-any.whl → 0.4.3__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 +6 -36
- openai_sdk_helpers/agent/__init__.py +3 -4
- openai_sdk_helpers/agent/base.py +34 -31
- openai_sdk_helpers/agent/{config.py → configuration.py} +13 -13
- openai_sdk_helpers/agent/{coordination.py → coordinator.py} +12 -10
- openai_sdk_helpers/agent/search/base.py +16 -16
- openai_sdk_helpers/agent/search/vector.py +25 -13
- openai_sdk_helpers/agent/search/web.py +5 -5
- openai_sdk_helpers/agent/summarizer.py +6 -4
- openai_sdk_helpers/agent/translator.py +9 -5
- openai_sdk_helpers/agent/{validation.py → validator.py} +6 -4
- openai_sdk_helpers/cli.py +8 -22
- openai_sdk_helpers/environment.py +8 -13
- 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 +1 -1
- openai_sdk_helpers/response/base.py +4 -4
- openai_sdk_helpers/response/{config.py → configuration.py} +8 -8
- openai_sdk_helpers/response/planner.py +1 -1
- openai_sdk_helpers/response/prompter.py +1 -1
- openai_sdk_helpers/streamlit_app/__init__.py +1 -1
- openai_sdk_helpers/streamlit_app/app.py +16 -17
- openai_sdk_helpers/streamlit_app/{config.py → configuration.py} +13 -13
- openai_sdk_helpers/streamlit_app/streamlit_web_search.py +2 -2
- openai_sdk_helpers/types.py +3 -3
- openai_sdk_helpers/utils/__init__.py +2 -6
- openai_sdk_helpers/utils/json/base_model.py +1 -1
- openai_sdk_helpers/utils/json/data_class.py +1 -1
- 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.4.3.dist-info}/METADATA +8 -8
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.4.3.dist-info}/RECORD +38 -40
- 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/utils/deprecation.py +0 -167
- /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.4.3.dist-info}/WHEEL +0 -0
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.4.3.dist-info}/entry_points.txt +0 -0
- {openai_sdk_helpers-0.4.2.dist-info → openai_sdk_helpers-0.4.3.dist-info}/licenses/LICENSE +0 -0
openai_sdk_helpers/__init__.py
CHANGED
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from .environment import get_data_path
|
|
5
|
+
from .environment import get_data_path
|
|
6
6
|
from .utils.async_utils import run_coroutine_thread_safe, run_coroutine_with_fallback
|
|
7
|
-
|
|
8
|
-
AsyncManagedResource,
|
|
9
|
-
ManagedResource,
|
|
10
|
-
async_context,
|
|
11
|
-
ensure_closed,
|
|
12
|
-
ensure_closed_async,
|
|
13
|
-
)
|
|
7
|
+
|
|
14
8
|
from .errors import (
|
|
15
9
|
OpenAISDKError,
|
|
16
10
|
ConfigurationError,
|
|
@@ -23,7 +17,7 @@ from .errors import (
|
|
|
23
17
|
AsyncExecutionError,
|
|
24
18
|
ResourceCleanupError,
|
|
25
19
|
)
|
|
26
|
-
|
|
20
|
+
|
|
27
21
|
from .utils.validation import (
|
|
28
22
|
validate_choice,
|
|
29
23
|
validate_dict_mapping,
|
|
@@ -51,7 +45,7 @@ from .structure import (
|
|
|
51
45
|
execute_plan,
|
|
52
46
|
)
|
|
53
47
|
from .prompt import PromptRenderer
|
|
54
|
-
from .
|
|
48
|
+
from .settings import OpenAISettings
|
|
55
49
|
from .files_api import FilesAPIManager, FilePurpose
|
|
56
50
|
from .vector_storage import VectorStorage, VectorStorageFileInfo, VectorStorageFileStats
|
|
57
51
|
from .agent import (
|
|
@@ -83,12 +77,7 @@ from .tools import (
|
|
|
83
77
|
ToolSpec,
|
|
84
78
|
build_tool_definitions,
|
|
85
79
|
)
|
|
86
|
-
from .
|
|
87
|
-
from .utils.deprecation import (
|
|
88
|
-
deprecated,
|
|
89
|
-
warn_deprecated,
|
|
90
|
-
DeprecationHelper,
|
|
91
|
-
)
|
|
80
|
+
from .settings import build_openai_settings
|
|
92
81
|
from .utils.output_validation import (
|
|
93
82
|
ValidationResult,
|
|
94
83
|
ValidationRule,
|
|
@@ -98,15 +87,11 @@ from .utils.output_validation import (
|
|
|
98
87
|
OutputValidator,
|
|
99
88
|
validate_output,
|
|
100
89
|
)
|
|
101
|
-
|
|
102
|
-
SupportsOpenAIClient,
|
|
103
|
-
OpenAIClient,
|
|
104
|
-
)
|
|
90
|
+
|
|
105
91
|
|
|
106
92
|
__all__ = [
|
|
107
93
|
# Environment utilities
|
|
108
94
|
"get_data_path",
|
|
109
|
-
"get_model",
|
|
110
95
|
# Async utilities
|
|
111
96
|
"run_coroutine_thread_safe",
|
|
112
97
|
"run_coroutine_with_fallback",
|
|
@@ -121,14 +106,6 @@ __all__ = [
|
|
|
121
106
|
"InputValidationError",
|
|
122
107
|
"AsyncExecutionError",
|
|
123
108
|
"ResourceCleanupError",
|
|
124
|
-
# Retry utilities
|
|
125
|
-
"with_exponential_backoff",
|
|
126
|
-
# Context managers
|
|
127
|
-
"ManagedResource",
|
|
128
|
-
"AsyncManagedResource",
|
|
129
|
-
"ensure_closed",
|
|
130
|
-
"ensure_closed_async",
|
|
131
|
-
"async_context",
|
|
132
109
|
# Validation
|
|
133
110
|
"validate_non_empty_string",
|
|
134
111
|
"validate_max_length",
|
|
@@ -184,13 +161,6 @@ __all__ = [
|
|
|
184
161
|
"create_plan",
|
|
185
162
|
"execute_task",
|
|
186
163
|
"execute_plan",
|
|
187
|
-
# Type definitions
|
|
188
|
-
"SupportsOpenAIClient",
|
|
189
|
-
"OpenAIClient",
|
|
190
|
-
# Deprecation utilities
|
|
191
|
-
"deprecated",
|
|
192
|
-
"warn_deprecated",
|
|
193
|
-
"DeprecationHelper",
|
|
194
164
|
# Output validation
|
|
195
165
|
"ValidationResult",
|
|
196
166
|
"ValidationRule",
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"""Shared agent helpers built on the OpenAI Agents SDK."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
|
|
5
4
|
from .base import AgentBase
|
|
6
|
-
from .
|
|
5
|
+
from .configuration import AgentConfiguration, AgentRegistry, get_default_registry
|
|
7
6
|
from ..structure.plan.enum import AgentEnum
|
|
8
|
-
from .
|
|
7
|
+
from .coordinator import CoordinatorAgent
|
|
9
8
|
from .runner import run_sync, run_async, run_streamed
|
|
10
9
|
from .search.base import SearchPlanner, SearchToolAgent, SearchWriter
|
|
11
10
|
from .summarizer import SummarizerAgent
|
|
12
11
|
from .translator import TranslatorAgent
|
|
13
|
-
from .
|
|
12
|
+
from .validator import ValidatorAgent
|
|
14
13
|
from .utils import run_coroutine_agent_sync
|
|
15
14
|
from .search.vector import VectorAgentSearch
|
|
16
15
|
from .search.web import WebAgentSearch
|
openai_sdk_helpers/agent/base.py
CHANGED
|
@@ -24,6 +24,7 @@ from ..utils.json.data_class import DataclassJSONSerializable
|
|
|
24
24
|
from ..structure.base import StructureBase
|
|
25
25
|
from ..structure.prompt import PromptStructure
|
|
26
26
|
|
|
27
|
+
|
|
27
28
|
from ..utils import (
|
|
28
29
|
check_filepath,
|
|
29
30
|
log,
|
|
@@ -34,7 +35,7 @@ from ..tools import tool_handler_factory
|
|
|
34
35
|
from .runner import run_async, run_streamed, run_sync
|
|
35
36
|
|
|
36
37
|
if TYPE_CHECKING:
|
|
37
|
-
from ..
|
|
38
|
+
from ..settings import OpenAISettings
|
|
38
39
|
from ..response.base import ResponseBase, ToolHandler
|
|
39
40
|
|
|
40
41
|
|
|
@@ -130,22 +131,22 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
130
131
|
Create a basic agent from configuration:
|
|
131
132
|
|
|
132
133
|
>>> from openai_sdk_helpers.agent import AgentBase, AgentConfiguration
|
|
133
|
-
>>>
|
|
134
|
+
>>> configuration = AgentConfiguration(
|
|
134
135
|
... name="my_agent",
|
|
135
136
|
... description="A custom agent",
|
|
136
137
|
... model="gpt-4o-mini"
|
|
137
138
|
... )
|
|
138
|
-
>>> agent = AgentBase(
|
|
139
|
+
>>> agent = AgentBase(configuration=configuration, default_model="gpt-4o-mini")
|
|
139
140
|
>>> result = agent.run_sync("What is 2+2?")
|
|
140
141
|
|
|
141
142
|
Use absolute path to template:
|
|
142
143
|
|
|
143
|
-
>>>
|
|
144
|
+
>>> configuration = AgentConfiguration(
|
|
144
145
|
... name="my_agent",
|
|
145
146
|
... template_path="/absolute/path/to/template.jinja",
|
|
146
147
|
... model="gpt-4o-mini"
|
|
147
148
|
... )
|
|
148
|
-
>>> agent = AgentBase(
|
|
149
|
+
>>> agent = AgentBase(configuration=configuration, default_model="gpt-4o-mini")
|
|
149
150
|
|
|
150
151
|
Use async execution:
|
|
151
152
|
|
|
@@ -200,7 +201,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
200
201
|
def __init__(
|
|
201
202
|
self,
|
|
202
203
|
*,
|
|
203
|
-
|
|
204
|
+
configuration: AgentConfigurationProtocol,
|
|
204
205
|
run_context_wrapper: Optional[RunContextWrapper[Dict[str, Any]]] = None,
|
|
205
206
|
data_path: Path | str | None = None,
|
|
206
207
|
prompt_dir: Optional[Path] = None,
|
|
@@ -210,29 +211,29 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
210
211
|
|
|
211
212
|
Parameters
|
|
212
213
|
----------
|
|
213
|
-
|
|
214
|
+
configuration : AgentConfigurationProtocol
|
|
214
215
|
Configuration describing this agent.
|
|
215
216
|
run_context_wrapper : RunContextWrapper or None, default=None
|
|
216
217
|
Optional wrapper providing runtime context for prompt rendering.
|
|
217
218
|
prompt_dir : Path or None, default=None
|
|
218
219
|
Optional directory holding prompt templates. Used when
|
|
219
|
-
``
|
|
220
|
-
``
|
|
220
|
+
``configuration.template_path`` is not provided or is relative. If
|
|
221
|
+
``configuration.template_path`` is an absolute path, this parameter is
|
|
221
222
|
ignored.
|
|
222
223
|
default_model : str or None, default=None
|
|
223
|
-
Optional fallback model identifier if the
|
|
224
|
+
Optional fallback model identifier if the configuration does not supply one.
|
|
224
225
|
"""
|
|
225
|
-
name =
|
|
226
|
-
description =
|
|
227
|
-
model =
|
|
226
|
+
name = configuration.name
|
|
227
|
+
description = configuration.description or ""
|
|
228
|
+
model = configuration.model or default_model
|
|
228
229
|
if not model:
|
|
229
230
|
raise ValueError("Model is required to construct the agent.")
|
|
230
231
|
|
|
231
|
-
prompt_path =
|
|
232
|
+
prompt_path = configuration.resolve_prompt_path(prompt_dir)
|
|
232
233
|
|
|
233
234
|
# Build template from file or fall back to instructions
|
|
234
235
|
if prompt_path is None:
|
|
235
|
-
instructions_text =
|
|
236
|
+
instructions_text = configuration.instructions_text
|
|
236
237
|
self._template = Template(instructions_text)
|
|
237
238
|
self._instructions = instructions_text
|
|
238
239
|
elif prompt_path.exists():
|
|
@@ -261,14 +262,16 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
261
262
|
|
|
262
263
|
self._data_path = get_data_path(self.__class__.__name__)
|
|
263
264
|
|
|
264
|
-
self._input_structure =
|
|
265
|
-
self._output_structure =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
self.
|
|
269
|
-
self.
|
|
270
|
-
self.
|
|
271
|
-
self.
|
|
265
|
+
self._input_structure = configuration.input_structure
|
|
266
|
+
self._output_structure = (
|
|
267
|
+
configuration.output_structure or configuration.input_structure
|
|
268
|
+
)
|
|
269
|
+
self._tools = configuration.tools
|
|
270
|
+
self._model_settings = configuration.model_settings
|
|
271
|
+
self._handoffs = configuration.handoffs
|
|
272
|
+
self._input_guardrails = configuration.input_guardrails
|
|
273
|
+
self._output_guardrails = configuration.output_guardrails
|
|
274
|
+
self._session = configuration.session
|
|
272
275
|
self._run_context_wrapper = run_context_wrapper
|
|
273
276
|
|
|
274
277
|
def _build_prompt_from_jinja(self) -> str:
|
|
@@ -474,7 +477,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
474
477
|
Optional type used to cast the final output.
|
|
475
478
|
session : Session or None, default=None
|
|
476
479
|
Optional session for maintaining conversation history across runs.
|
|
477
|
-
If not provided, uses the session from
|
|
480
|
+
If not provided, uses the session from configuration if available.
|
|
478
481
|
|
|
479
482
|
Returns
|
|
480
483
|
-------
|
|
@@ -483,7 +486,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
483
486
|
"""
|
|
484
487
|
if self._output_structure is not None and output_structure is None:
|
|
485
488
|
output_structure = self._output_structure
|
|
486
|
-
# Use session from parameter, fall back to
|
|
489
|
+
# Use session from parameter, fall back to configuration session
|
|
487
490
|
session_to_use = session if session is not None else self._session
|
|
488
491
|
return await run_async(
|
|
489
492
|
agent=self.get_agent(),
|
|
@@ -513,7 +516,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
513
516
|
Optional type used to cast the final output.
|
|
514
517
|
session : Session or None, default=None
|
|
515
518
|
Optional session for maintaining conversation history across runs.
|
|
516
|
-
If not provided, uses the session from
|
|
519
|
+
If not provided, uses the session from configuration if available.
|
|
517
520
|
|
|
518
521
|
Returns
|
|
519
522
|
-------
|
|
@@ -522,7 +525,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
522
525
|
"""
|
|
523
526
|
if self._output_structure is not None and output_structure is None:
|
|
524
527
|
output_structure = self._output_structure
|
|
525
|
-
# Use session from parameter, fall back to
|
|
528
|
+
# Use session from parameter, fall back to configuration session
|
|
526
529
|
session_to_use = session if session is not None else self._session
|
|
527
530
|
return run_sync(
|
|
528
531
|
agent=self.get_agent(),
|
|
@@ -552,14 +555,14 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
552
555
|
Optional type used to cast the final output.
|
|
553
556
|
session : Session or None, default=None
|
|
554
557
|
Optional session for maintaining conversation history across runs.
|
|
555
|
-
If not provided, uses the session from
|
|
558
|
+
If not provided, uses the session from configuration if available.
|
|
556
559
|
|
|
557
560
|
Returns
|
|
558
561
|
-------
|
|
559
562
|
RunResultStreaming
|
|
560
563
|
Streaming output wrapper from the agent execution.
|
|
561
564
|
"""
|
|
562
|
-
# Use session from parameter, fall back to
|
|
565
|
+
# Use session from parameter, fall back to configuration session
|
|
563
566
|
session_to_use = session if session is not None else self._session
|
|
564
567
|
output_structure_to_use = output_structure or self._output_structure
|
|
565
568
|
result = run_streamed(
|
|
@@ -682,7 +685,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
682
685
|
>>> response = agent.build_response(openai_settings=OpenAISettings.from_env())
|
|
683
686
|
"""
|
|
684
687
|
from ..response.base import ResponseBase, ToolHandler
|
|
685
|
-
from ..
|
|
688
|
+
from ..settings import OpenAISettings
|
|
686
689
|
|
|
687
690
|
if not isinstance(openai_settings, OpenAISettings):
|
|
688
691
|
raise TypeError("openai_settings must be an OpenAISettings instance")
|
|
@@ -770,7 +773,7 @@ class AgentBase(DataclassJSONSerializable):
|
|
|
770
773
|
|
|
771
774
|
Examples
|
|
772
775
|
--------
|
|
773
|
-
>>> agent = AgentBase(
|
|
776
|
+
>>> agent = AgentBase(configuration, default_model="gpt-4o-mini")
|
|
774
777
|
>>> try:
|
|
775
778
|
... result = agent.run_sync("query")
|
|
776
779
|
... finally:
|
|
@@ -24,12 +24,12 @@ class AgentRegistry(RegistryBase["AgentConfiguration"]):
|
|
|
24
24
|
Examples
|
|
25
25
|
--------
|
|
26
26
|
>>> registry = AgentRegistry()
|
|
27
|
-
>>>
|
|
27
|
+
>>> configuration = AgentConfiguration(
|
|
28
28
|
... name="test_agent",
|
|
29
29
|
... model="gpt-4o-mini",
|
|
30
30
|
... instructions="Test instructions"
|
|
31
31
|
... )
|
|
32
|
-
>>> registry.register(
|
|
32
|
+
>>> registry.register(configuration)
|
|
33
33
|
>>> retrieved = registry.get("test_agent")
|
|
34
34
|
>>> retrieved.name
|
|
35
35
|
'test_agent'
|
|
@@ -85,10 +85,10 @@ def get_default_registry() -> AgentRegistry:
|
|
|
85
85
|
Examples
|
|
86
86
|
--------
|
|
87
87
|
>>> registry = get_default_registry()
|
|
88
|
-
>>>
|
|
88
|
+
>>> configuration = AgentConfiguration(
|
|
89
89
|
... name="test", model="gpt-4o-mini", instructions="Test instructions"
|
|
90
90
|
... )
|
|
91
|
-
>>> registry.register(
|
|
91
|
+
>>> registry.register(configuration)
|
|
92
92
|
"""
|
|
93
93
|
return _default_registry
|
|
94
94
|
|
|
@@ -165,12 +165,12 @@ class AgentConfiguration(DataclassJSONSerializable):
|
|
|
165
165
|
|
|
166
166
|
Examples
|
|
167
167
|
--------
|
|
168
|
-
>>>
|
|
168
|
+
>>> configuration = AgentConfiguration(
|
|
169
169
|
... name="summarizer",
|
|
170
170
|
... description="Summarizes text",
|
|
171
171
|
... model="gpt-4o-mini"
|
|
172
172
|
... )
|
|
173
|
-
>>>
|
|
173
|
+
>>> configuration.name
|
|
174
174
|
'summarizer'
|
|
175
175
|
"""
|
|
176
176
|
|
|
@@ -308,7 +308,7 @@ class AgentConfiguration(DataclassJSONSerializable):
|
|
|
308
308
|
prompt_dir : Path or None, default=None
|
|
309
309
|
Optional directory holding prompt templates.
|
|
310
310
|
default_model : str or None, default=None
|
|
311
|
-
Optional fallback model identifier if
|
|
311
|
+
Optional fallback model identifier if configuration doesn't specify one.
|
|
312
312
|
|
|
313
313
|
Returns
|
|
314
314
|
-------
|
|
@@ -317,17 +317,17 @@ class AgentConfiguration(DataclassJSONSerializable):
|
|
|
317
317
|
|
|
318
318
|
Examples
|
|
319
319
|
--------
|
|
320
|
-
>>>
|
|
320
|
+
>>> configuration = AgentConfiguration(
|
|
321
321
|
... name="helper", model="gpt-4o-mini", instructions="Help the user"
|
|
322
322
|
... )
|
|
323
|
-
>>> agent =
|
|
323
|
+
>>> agent = configuration.gen_agent()
|
|
324
324
|
>>> result = agent.run_sync("Hello!")
|
|
325
325
|
"""
|
|
326
326
|
# Import here to avoid circular dependency
|
|
327
327
|
from .base import AgentBase
|
|
328
328
|
|
|
329
329
|
return AgentBase(
|
|
330
|
-
|
|
330
|
+
configuration=self,
|
|
331
331
|
run_context_wrapper=run_context_wrapper,
|
|
332
332
|
prompt_dir=prompt_dir,
|
|
333
333
|
default_model=default_model,
|
|
@@ -352,10 +352,10 @@ class AgentConfiguration(DataclassJSONSerializable):
|
|
|
352
352
|
|
|
353
353
|
Examples
|
|
354
354
|
--------
|
|
355
|
-
>>>
|
|
355
|
+
>>> configuration = AgentConfiguration(
|
|
356
356
|
... name="agent1", model="gpt-4o-mini", instructions="Agent instructions"
|
|
357
357
|
... )
|
|
358
|
-
>>> config2 =
|
|
358
|
+
>>> config2 = configuration.replace(name="agent2", description="Modified")
|
|
359
359
|
>>> config2.name
|
|
360
360
|
'agent2'
|
|
361
361
|
>>> config2.model
|
|
@@ -387,7 +387,7 @@ class AgentConfiguration(DataclassJSONSerializable):
|
|
|
387
387
|
>>> response_config.name
|
|
388
388
|
'responder'
|
|
389
389
|
"""
|
|
390
|
-
from ..response.
|
|
390
|
+
from ..response.configuration import ResponseConfiguration
|
|
391
391
|
|
|
392
392
|
return ResponseConfiguration(
|
|
393
393
|
name=self.name,
|
|
@@ -11,11 +11,11 @@ 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
|
-
|
|
17
|
+
from .configuration import AgentConfiguration
|
|
18
|
+
|
|
19
19
|
|
|
20
20
|
PromptFn = Callable[[str], PromptStructure]
|
|
21
21
|
BuildPlanFn = Callable[[str], PlanStructure]
|
|
@@ -40,7 +40,7 @@ class CoordinatorAgent(AgentBase):
|
|
|
40
40
|
Base path for persisting project artifacts.
|
|
41
41
|
name : str
|
|
42
42
|
Name of the parent module for data organization.
|
|
43
|
-
|
|
43
|
+
configuration : AgentConfiguration or None, default=None
|
|
44
44
|
Optional agent configuration describing prompts and metadata.
|
|
45
45
|
prompt_dir : Path or None, default=None
|
|
46
46
|
Optional directory holding prompt templates.
|
|
@@ -84,7 +84,7 @@ class CoordinatorAgent(AgentBase):
|
|
|
84
84
|
summarize_fn: SummarizeFn,
|
|
85
85
|
module_data_path: Path,
|
|
86
86
|
name: str,
|
|
87
|
-
|
|
87
|
+
configuration: Optional[AgentConfiguration] = None,
|
|
88
88
|
prompt_dir: Optional[Path] = None,
|
|
89
89
|
default_model: Optional[str] = None,
|
|
90
90
|
) -> None:
|
|
@@ -104,7 +104,7 @@ class CoordinatorAgent(AgentBase):
|
|
|
104
104
|
Base path for persisting project artifacts.
|
|
105
105
|
name : str
|
|
106
106
|
Name of the parent module for data organization.
|
|
107
|
-
|
|
107
|
+
configuration : AgentConfiguration or None, default=None
|
|
108
108
|
Optional agent configuration describing prompts and metadata.
|
|
109
109
|
prompt_dir : Path or None, default=None
|
|
110
110
|
Optional directory holding prompt templates.
|
|
@@ -127,14 +127,16 @@ class CoordinatorAgent(AgentBase):
|
|
|
127
127
|
... name="test",
|
|
128
128
|
... )
|
|
129
129
|
"""
|
|
130
|
-
if
|
|
131
|
-
|
|
130
|
+
if configuration is None:
|
|
131
|
+
configuration = AgentConfiguration(
|
|
132
132
|
name="coordinator_agent",
|
|
133
133
|
instructions="Coordinate agents for planning and summarization.",
|
|
134
134
|
description="Coordinates agents for planning and summarization.",
|
|
135
135
|
)
|
|
136
136
|
super().__init__(
|
|
137
|
-
|
|
137
|
+
configuration=configuration,
|
|
138
|
+
prompt_dir=prompt_dir,
|
|
139
|
+
default_model=default_model,
|
|
138
140
|
)
|
|
139
141
|
self._prompt_fn = prompt_fn
|
|
140
142
|
self._build_plan_fn = build_plan_fn
|
|
@@ -13,7 +13,7 @@ from pathlib import Path
|
|
|
13
13
|
from typing import 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
|
|
@@ -36,7 +36,7 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
|
|
|
36
36
|
prompt_dir : Path, optional
|
|
37
37
|
Directory containing prompt templates.
|
|
38
38
|
default_model : str, optional
|
|
39
|
-
Default model identifier to use when not defined in
|
|
39
|
+
Default model identifier to use when not defined in configuration.
|
|
40
40
|
|
|
41
41
|
Methods
|
|
42
42
|
-------
|
|
@@ -68,9 +68,9 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
|
|
|
68
68
|
default_model: Optional[str] = None,
|
|
69
69
|
) -> None:
|
|
70
70
|
"""Initialize the planner agent."""
|
|
71
|
-
|
|
71
|
+
configuration = self._configure_agent()
|
|
72
72
|
super().__init__(
|
|
73
|
-
|
|
73
|
+
configuration=configuration,
|
|
74
74
|
prompt_dir=prompt_dir,
|
|
75
75
|
default_model=default_model,
|
|
76
76
|
)
|
|
@@ -86,12 +86,12 @@ class SearchPlanner(AgentBase, Generic[PlanType]):
|
|
|
86
86
|
|
|
87
87
|
Examples
|
|
88
88
|
--------
|
|
89
|
-
>>>
|
|
89
|
+
>>> configuration = AgentConfiguration(
|
|
90
90
|
... name="web_planner",
|
|
91
91
|
... description="Plan web searches",
|
|
92
92
|
... output_structure=WebSearchPlanStructure,
|
|
93
93
|
... )
|
|
94
|
-
>>> return
|
|
94
|
+
>>> return configuration
|
|
95
95
|
"""
|
|
96
96
|
pass
|
|
97
97
|
|
|
@@ -127,7 +127,7 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
|
|
|
127
127
|
prompt_dir : Path, optional
|
|
128
128
|
Directory containing prompt templates.
|
|
129
129
|
default_model : str, optional
|
|
130
|
-
Default model identifier to use when not defined in
|
|
130
|
+
Default model identifier to use when not defined in configuration.
|
|
131
131
|
max_concurrent_searches : int, default=10
|
|
132
132
|
Maximum number of concurrent search operations.
|
|
133
133
|
|
|
@@ -168,9 +168,9 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
|
|
|
168
168
|
) -> None:
|
|
169
169
|
"""Initialize the search tool agent."""
|
|
170
170
|
self._max_concurrent_searches = max_concurrent_searches
|
|
171
|
-
|
|
171
|
+
configuration = self._configure_agent()
|
|
172
172
|
super().__init__(
|
|
173
|
-
|
|
173
|
+
configuration=configuration,
|
|
174
174
|
prompt_dir=prompt_dir,
|
|
175
175
|
default_model=default_model,
|
|
176
176
|
)
|
|
@@ -186,13 +186,13 @@ class SearchToolAgent(AgentBase, Generic[ItemType, ResultType, PlanType]):
|
|
|
186
186
|
|
|
187
187
|
Examples
|
|
188
188
|
--------
|
|
189
|
-
>>>
|
|
189
|
+
>>> configuration = AgentConfiguration(
|
|
190
190
|
... name="web_search",
|
|
191
191
|
... description="Perform web searches",
|
|
192
192
|
... input_structure=WebSearchPlanStructure,
|
|
193
193
|
... tools=[WebSearchTool()],
|
|
194
194
|
... )
|
|
195
|
-
>>> return
|
|
195
|
+
>>> return configuration
|
|
196
196
|
"""
|
|
197
197
|
pass
|
|
198
198
|
|
|
@@ -250,7 +250,7 @@ class SearchWriter(AgentBase, Generic[ReportType]):
|
|
|
250
250
|
prompt_dir : Path, optional
|
|
251
251
|
Directory containing prompt templates.
|
|
252
252
|
default_model : str, optional
|
|
253
|
-
Default model identifier to use when not defined in
|
|
253
|
+
Default model identifier to use when not defined in configuration.
|
|
254
254
|
|
|
255
255
|
Methods
|
|
256
256
|
-------
|
|
@@ -282,9 +282,9 @@ class SearchWriter(AgentBase, Generic[ReportType]):
|
|
|
282
282
|
default_model: Optional[str] = None,
|
|
283
283
|
) -> None:
|
|
284
284
|
"""Initialize the writer agent."""
|
|
285
|
-
|
|
285
|
+
configuration = self._configure_agent()
|
|
286
286
|
super().__init__(
|
|
287
|
-
|
|
287
|
+
configuration=configuration,
|
|
288
288
|
prompt_dir=prompt_dir,
|
|
289
289
|
default_model=default_model,
|
|
290
290
|
)
|
|
@@ -300,12 +300,12 @@ class SearchWriter(AgentBase, Generic[ReportType]):
|
|
|
300
300
|
|
|
301
301
|
Examples
|
|
302
302
|
--------
|
|
303
|
-
>>>
|
|
303
|
+
>>> configuration = AgentConfiguration(
|
|
304
304
|
... name="web_writer",
|
|
305
305
|
... description="Write web search report",
|
|
306
306
|
... output_structure=WebSearchReportStructure,
|
|
307
307
|
... )
|
|
308
|
-
>>> return
|
|
308
|
+
>>> return configuration
|
|
309
309
|
"""
|
|
310
310
|
pass
|
|
311
311
|
|