openai-sdk-helpers 0.0.2__tar.gz → 0.0.4__tar.gz
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-0.0.2 → openai_sdk_helpers-0.0.4}/PKG-INFO +57 -4
- {openai_sdk_helpers-0.0.2 → openai_sdk_helpers-0.0.4}/README.md +56 -3
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/__init__.py +62 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/__init__.py +31 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/base.py +46 -148
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/config.py +2 -2
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/project_manager.py +125 -30
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/prompt_utils.py +9 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/runner.py +215 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/summarizer.py +85 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/translator.py +139 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/utils.py +2 -2
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/agent/validation.py +97 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/vector_search.py +67 -23
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/web_search.py +18 -18
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/config.py +13 -1
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/enums/base.py +29 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/prompt/summarizer.jinja +7 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/prompt/translator.jinja +7 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/prompt/validator.jinja +7 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/py.typed +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/response/__init__.py +4 -2
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/response/base.py +34 -10
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/response/runner.py +104 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/__init__.py +11 -25
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/structure/agent_blueprint.py +224 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/base.py +158 -36
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/plan/__init__.py +4 -4
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/plan/enum.py +16 -0
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/structure/plan/plan.py +253 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/plan/task.py +5 -5
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/responses.py +7 -23
- openai_sdk_helpers-0.0.4/openai_sdk_helpers/structure/validation.py +47 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/vector_search.py +4 -0
- {openai_sdk_helpers-0.0.2 → openai_sdk_helpers-0.0.4}/pyproject.toml +3 -2
- openai_sdk_helpers-0.0.2/.github/dependabot.yml +0 -10
- openai_sdk_helpers-0.0.2/.github/workflows/ci.yml +0 -44
- openai_sdk_helpers-0.0.2/.github/workflows/python-publish.yml +0 -39
- openai_sdk_helpers-0.0.2/AGENTS.md +0 -82
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/__init__.py +0 -34
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/agent/__init__.py +0 -23
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/agent/runner.py +0 -117
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/enums/base.py +0 -17
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/response/runner.py +0 -42
- openai_sdk_helpers-0.0.2/src/openai_sdk_helpers/structure/plan/plan.py +0 -104
- openai_sdk_helpers-0.0.2/tests/agent/test_agent_base.py +0 -116
- openai_sdk_helpers-0.0.2/tests/agent/test_agent_runner.py +0 -45
- openai_sdk_helpers-0.0.2/tests/agent/test_agent_utils.py +0 -27
- openai_sdk_helpers-0.0.2/tests/agent/test_project_manager.py +0 -159
- openai_sdk_helpers-0.0.2/tests/conftest.py +0 -12
- openai_sdk_helpers-0.0.2/tests/response/test_response_base.py +0 -31
- openai_sdk_helpers-0.0.2/tests/response/test_response_base_unit.py +0 -63
- openai_sdk_helpers-0.0.2/tests/structure/test_structure_base.py +0 -148
- openai_sdk_helpers-0.0.2/tests/test_config.py +0 -58
- openai_sdk_helpers-0.0.2/tests/test_imports.py +0 -21
- openai_sdk_helpers-0.0.2/tests/test_integration.py +0 -57
- openai_sdk_helpers-0.0.2/tests/test_prompt_renderer.py +0 -26
- openai_sdk_helpers-0.0.2/tests/test_utils.py +0 -108
- openai_sdk_helpers-0.0.2/tests/test_vector_types.py +0 -35
- openai_sdk_helpers-0.0.2/tests/vector_storage/test_cleanup.py +0 -116
- openai_sdk_helpers-0.0.2/tests/vector_storage/test_storage.py +0 -163
- openai_sdk_helpers-0.0.2/tests/vector_storage/test_vector_storage.py +0 -64
- {openai_sdk_helpers-0.0.2 → openai_sdk_helpers-0.0.4}/.gitignore +0 -0
- {openai_sdk_helpers-0.0.2 → openai_sdk_helpers-0.0.4}/LICENSE +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/enums/__init__.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/environment.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/prompt/__init__.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/response/messages.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/response/tool_call.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/prompt.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/summary.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/structure/web_search.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/utils/__init__.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/utils/core.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/vector_storage/__init__.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/vector_storage/cleanup.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/vector_storage/storage.py +0 -0
- {openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/vector_storage/types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openai-sdk-helpers
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: Composable helpers for OpenAI SDK agents, prompts, and storage
|
|
5
5
|
Author: openai-sdk-helpers maintainers
|
|
6
6
|
License: MIT
|
|
@@ -39,6 +39,7 @@ application-specific prompts and tools to the consuming project.
|
|
|
39
39
|
predictable inputs and outputs.
|
|
40
40
|
- **Vector and web search flows** that coordinate planning, execution, and
|
|
41
41
|
reporting.
|
|
42
|
+
- **Reusable text agents** for summarization and translation tasks.
|
|
42
43
|
|
|
43
44
|
## Installation
|
|
44
45
|
|
|
@@ -48,6 +49,9 @@ Install the package directly from PyPI to reuse it across projects:
|
|
|
48
49
|
pip install openai-sdk-helpers
|
|
49
50
|
```
|
|
50
51
|
|
|
52
|
+
Type information ships with the published wheel via `py.typed`, so external
|
|
53
|
+
projects can rely on the bundled annotations without adding custom stubs.
|
|
54
|
+
|
|
51
55
|
For local development, install with editable sources and the optional dev
|
|
52
56
|
dependencies:
|
|
53
57
|
|
|
@@ -74,9 +78,39 @@ report = vector_search.run_agent_sync("Explain quantum entanglement for beginner
|
|
|
74
78
|
print(report.report)
|
|
75
79
|
```
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
### Text utilities
|
|
82
|
+
|
|
83
|
+
Use the built-in text helpers when you need lightweight single-step agents.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from openai_sdk_helpers.agent import (
|
|
87
|
+
SummarizerAgent,
|
|
88
|
+
TranslatorAgent,
|
|
89
|
+
ValidatorAgent,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
summarizer = SummarizerAgent(default_model="gpt-4o-mini")
|
|
94
|
+
translator = TranslatorAgent(default_model="gpt-4o-mini")
|
|
95
|
+
validator = ValidatorAgent(default_model="gpt-4o-mini")
|
|
96
|
+
|
|
97
|
+
summary = summarizer.run_sync("Long-form content to condense")
|
|
98
|
+
translation = translator.run_sync("Bonjour", target_language="English")
|
|
99
|
+
guardrails = validator.run_sync(
|
|
100
|
+
"Share meeting notes with names removed", agent_output=summary.text
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Prompt templates are optional for the built-in text helpers. They already ship
|
|
105
|
+
with defaults under `src/openai_sdk_helpers/prompt`, so you do **not** need to
|
|
106
|
+
create placeholder files when installing from PyPI. Only pass a `prompt_dir`
|
|
107
|
+
when you have real replacements you want to load.
|
|
108
|
+
|
|
109
|
+
The vector search workflow expects real prompts for each agent (for example,
|
|
110
|
+
`vector_planner.jinja`, `vector_search.jinja`, and `vector_writer.jinja`). If
|
|
111
|
+
you point `prompt_dir` at a folder that does not contain those files, agent
|
|
112
|
+
construction fails with a `FileNotFoundError`. Skip `prompt_dir` entirely unless
|
|
113
|
+
you have working templates ready.
|
|
80
114
|
|
|
81
115
|
### Centralized OpenAI configuration
|
|
82
116
|
|
|
@@ -129,6 +163,25 @@ pytest -q --cov=src --cov-report=term-missing --cov-fail-under=70
|
|
|
129
163
|
- `src/openai_sdk_helpers/vector_storage`: Minimal vector store abstraction.
|
|
130
164
|
- `tests/`: Unit tests covering core modules and structures.
|
|
131
165
|
|
|
166
|
+
## Key modules
|
|
167
|
+
|
|
168
|
+
The package centers around a handful of cohesive building blocks:
|
|
169
|
+
|
|
170
|
+
- `openai_sdk_helpers.agent.project_manager.ProjectManager` coordinates prompt
|
|
171
|
+
creation, plan building, task execution, and summarization while persisting
|
|
172
|
+
intermediate artifacts to disk.
|
|
173
|
+
- `openai_sdk_helpers.agent.vector_search.VectorSearch` bundles the planners,
|
|
174
|
+
executors, and summarizers required to run a multi-turn vector search flow
|
|
175
|
+
from a single entry point.
|
|
176
|
+
- `openai_sdk_helpers.agent.summarizer.SummarizerAgent`,
|
|
177
|
+
`agent.translator.TranslatorAgent`, and `agent.validator.ValidatorAgent`
|
|
178
|
+
expose streamlined text-processing utilities that reuse shared prompt
|
|
179
|
+
templates.
|
|
180
|
+
- `openai_sdk_helpers.response` contains the response runners and helpers used
|
|
181
|
+
to normalize outputs from agents, including streaming responses.
|
|
182
|
+
- `openai_sdk_helpers.utils` holds JSON serialization helpers, logging
|
|
183
|
+
utilities, and common validation helpers used across modules.
|
|
184
|
+
|
|
132
185
|
## Contributing
|
|
133
186
|
|
|
134
187
|
Contributions are welcome! Please accompany functional changes with relevant
|
|
@@ -23,6 +23,7 @@ application-specific prompts and tools to the consuming project.
|
|
|
23
23
|
predictable inputs and outputs.
|
|
24
24
|
- **Vector and web search flows** that coordinate planning, execution, and
|
|
25
25
|
reporting.
|
|
26
|
+
- **Reusable text agents** for summarization and translation tasks.
|
|
26
27
|
|
|
27
28
|
## Installation
|
|
28
29
|
|
|
@@ -32,6 +33,9 @@ Install the package directly from PyPI to reuse it across projects:
|
|
|
32
33
|
pip install openai-sdk-helpers
|
|
33
34
|
```
|
|
34
35
|
|
|
36
|
+
Type information ships with the published wheel via `py.typed`, so external
|
|
37
|
+
projects can rely on the bundled annotations without adding custom stubs.
|
|
38
|
+
|
|
35
39
|
For local development, install with editable sources and the optional dev
|
|
36
40
|
dependencies:
|
|
37
41
|
|
|
@@ -58,9 +62,39 @@ report = vector_search.run_agent_sync("Explain quantum entanglement for beginner
|
|
|
58
62
|
print(report.report)
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
### Text utilities
|
|
66
|
+
|
|
67
|
+
Use the built-in text helpers when you need lightweight single-step agents.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from openai_sdk_helpers.agent import (
|
|
71
|
+
SummarizerAgent,
|
|
72
|
+
TranslatorAgent,
|
|
73
|
+
ValidatorAgent,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
summarizer = SummarizerAgent(default_model="gpt-4o-mini")
|
|
78
|
+
translator = TranslatorAgent(default_model="gpt-4o-mini")
|
|
79
|
+
validator = ValidatorAgent(default_model="gpt-4o-mini")
|
|
80
|
+
|
|
81
|
+
summary = summarizer.run_sync("Long-form content to condense")
|
|
82
|
+
translation = translator.run_sync("Bonjour", target_language="English")
|
|
83
|
+
guardrails = validator.run_sync(
|
|
84
|
+
"Share meeting notes with names removed", agent_output=summary.text
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Prompt templates are optional for the built-in text helpers. They already ship
|
|
89
|
+
with defaults under `src/openai_sdk_helpers/prompt`, so you do **not** need to
|
|
90
|
+
create placeholder files when installing from PyPI. Only pass a `prompt_dir`
|
|
91
|
+
when you have real replacements you want to load.
|
|
92
|
+
|
|
93
|
+
The vector search workflow expects real prompts for each agent (for example,
|
|
94
|
+
`vector_planner.jinja`, `vector_search.jinja`, and `vector_writer.jinja`). If
|
|
95
|
+
you point `prompt_dir` at a folder that does not contain those files, agent
|
|
96
|
+
construction fails with a `FileNotFoundError`. Skip `prompt_dir` entirely unless
|
|
97
|
+
you have working templates ready.
|
|
64
98
|
|
|
65
99
|
### Centralized OpenAI configuration
|
|
66
100
|
|
|
@@ -113,6 +147,25 @@ pytest -q --cov=src --cov-report=term-missing --cov-fail-under=70
|
|
|
113
147
|
- `src/openai_sdk_helpers/vector_storage`: Minimal vector store abstraction.
|
|
114
148
|
- `tests/`: Unit tests covering core modules and structures.
|
|
115
149
|
|
|
150
|
+
## Key modules
|
|
151
|
+
|
|
152
|
+
The package centers around a handful of cohesive building blocks:
|
|
153
|
+
|
|
154
|
+
- `openai_sdk_helpers.agent.project_manager.ProjectManager` coordinates prompt
|
|
155
|
+
creation, plan building, task execution, and summarization while persisting
|
|
156
|
+
intermediate artifacts to disk.
|
|
157
|
+
- `openai_sdk_helpers.agent.vector_search.VectorSearch` bundles the planners,
|
|
158
|
+
executors, and summarizers required to run a multi-turn vector search flow
|
|
159
|
+
from a single entry point.
|
|
160
|
+
- `openai_sdk_helpers.agent.summarizer.SummarizerAgent`,
|
|
161
|
+
`agent.translator.TranslatorAgent`, and `agent.validator.ValidatorAgent`
|
|
162
|
+
expose streamlined text-processing utilities that reuse shared prompt
|
|
163
|
+
templates.
|
|
164
|
+
- `openai_sdk_helpers.response` contains the response runners and helpers used
|
|
165
|
+
to normalize outputs from agents, including streaming responses.
|
|
166
|
+
- `openai_sdk_helpers.utils` holds JSON serialization helpers, logging
|
|
167
|
+
utilities, and common validation helpers used across modules.
|
|
168
|
+
|
|
116
169
|
## Contributing
|
|
117
170
|
|
|
118
171
|
Contributions are welcome! Please accompany functional changes with relevant
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Shared AI helpers and base structures."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .structure import *
|
|
6
|
+
from .prompt import PromptRenderer
|
|
7
|
+
from .config import OpenAISettings
|
|
8
|
+
from .vector_storage import *
|
|
9
|
+
from .agent import (
|
|
10
|
+
AgentBase,
|
|
11
|
+
AgentConfig,
|
|
12
|
+
AgentEnum,
|
|
13
|
+
ProjectManager,
|
|
14
|
+
SummarizerAgent,
|
|
15
|
+
TranslatorAgent,
|
|
16
|
+
ValidatorAgent,
|
|
17
|
+
VectorSearch,
|
|
18
|
+
WebAgentSearch,
|
|
19
|
+
)
|
|
20
|
+
from .response import (
|
|
21
|
+
ResponseBase,
|
|
22
|
+
ResponseMessage,
|
|
23
|
+
ResponseMessages,
|
|
24
|
+
ResponseToolCall,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"BaseStructure",
|
|
29
|
+
"SchemaOptions",
|
|
30
|
+
"spec_field",
|
|
31
|
+
"PromptRenderer",
|
|
32
|
+
"OpenAISettings",
|
|
33
|
+
"VectorStorage",
|
|
34
|
+
"VectorStorageFileInfo",
|
|
35
|
+
"VectorStorageFileStats",
|
|
36
|
+
"assistant_tool_definition",
|
|
37
|
+
"assistant_format",
|
|
38
|
+
"response_tool_definition",
|
|
39
|
+
"response_format",
|
|
40
|
+
"SummaryStructure",
|
|
41
|
+
"PromptStructure",
|
|
42
|
+
"AgentBlueprint",
|
|
43
|
+
"TaskStructure",
|
|
44
|
+
"PlanStructure",
|
|
45
|
+
"AgentEnum",
|
|
46
|
+
"AgentBase",
|
|
47
|
+
"AgentConfig",
|
|
48
|
+
"ProjectManager",
|
|
49
|
+
"SummarizerAgent",
|
|
50
|
+
"TranslatorAgent",
|
|
51
|
+
"ValidatorAgent",
|
|
52
|
+
"VectorSearch",
|
|
53
|
+
"WebAgentSearch",
|
|
54
|
+
"ExtendedSummaryStructure",
|
|
55
|
+
"WebSearchStructure",
|
|
56
|
+
"VectorSearchStructure",
|
|
57
|
+
"ValidationResultStructure",
|
|
58
|
+
"ResponseBase",
|
|
59
|
+
"ResponseMessage",
|
|
60
|
+
"ResponseMessages",
|
|
61
|
+
"ResponseToolCall",
|
|
62
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Shared agent helpers built on the OpenAI Agents SDK."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .base import AgentBase
|
|
6
|
+
from .config import AgentConfig
|
|
7
|
+
from ..structure.plan.enum import AgentEnum
|
|
8
|
+
from .project_manager import ProjectManager
|
|
9
|
+
from .runner import run_sync, run_async, run_streamed
|
|
10
|
+
from .summarizer import SummarizerAgent
|
|
11
|
+
from .translator import TranslatorAgent
|
|
12
|
+
from .validation import ValidatorAgent
|
|
13
|
+
from .utils import run_coroutine_agent_sync
|
|
14
|
+
from .vector_search import VectorSearch
|
|
15
|
+
from .web_search import WebAgentSearch
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"AgentBase",
|
|
19
|
+
"AgentConfig",
|
|
20
|
+
"AgentEnum",
|
|
21
|
+
"ProjectManager",
|
|
22
|
+
"run_sync",
|
|
23
|
+
"run_async",
|
|
24
|
+
"run_streamed",
|
|
25
|
+
"run_coroutine_agent_sync",
|
|
26
|
+
"SummarizerAgent",
|
|
27
|
+
"TranslatorAgent",
|
|
28
|
+
"ValidatorAgent",
|
|
29
|
+
"VectorSearch",
|
|
30
|
+
"WebAgentSearch",
|
|
31
|
+
]
|
|
@@ -11,10 +11,11 @@ from agents import Agent, Runner, RunResult, RunResultStreaming
|
|
|
11
11
|
from agents.run_context import RunContextWrapper
|
|
12
12
|
from agents.tool import FunctionTool
|
|
13
13
|
from jinja2 import Template
|
|
14
|
+
from .runner import run_sync, run_streamed, run_async
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class AgentConfigLike(Protocol):
|
|
17
|
-
"""Protocol describing the configuration attributes for
|
|
18
|
+
"""Protocol describing the configuration attributes for AgentBase."""
|
|
18
19
|
|
|
19
20
|
name: str
|
|
20
21
|
description: Optional[str]
|
|
@@ -26,24 +27,26 @@ class AgentConfigLike(Protocol):
|
|
|
26
27
|
model_settings: Optional[Any]
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
class
|
|
30
|
+
class AgentBase:
|
|
30
31
|
"""Factory for creating and configuring specialized agents.
|
|
31
32
|
|
|
32
33
|
Methods
|
|
33
34
|
-------
|
|
34
35
|
from_config(config, run_context_wrapper)
|
|
35
|
-
Instantiate a ``
|
|
36
|
+
Instantiate a ``AgentBase`` from configuration.
|
|
36
37
|
build_prompt_from_jinja(run_context_wrapper)
|
|
37
38
|
Render the agent prompt using Jinja and optional context.
|
|
38
39
|
get_prompt(run_context_wrapper, _)
|
|
39
40
|
Render the agent prompt using the provided run context.
|
|
40
41
|
get_agent()
|
|
41
42
|
Construct the configured :class:`agents.Agent` instance.
|
|
42
|
-
run(
|
|
43
|
+
run(input, context, output_type)
|
|
44
|
+
Execute the agent asynchronously (alias of ``run_async``).
|
|
45
|
+
run_async(input, context, output_type)
|
|
43
46
|
Execute the agent asynchronously and optionally cast the result.
|
|
44
|
-
run_sync(
|
|
47
|
+
run_sync(input, context, output_type)
|
|
45
48
|
Execute the agent synchronously.
|
|
46
|
-
run_streamed(
|
|
49
|
+
run_streamed(input, context, output_type)
|
|
47
50
|
Return a streaming result for the agent execution.
|
|
48
51
|
as_tool()
|
|
49
52
|
Return the agent as a callable tool.
|
|
@@ -56,7 +59,7 @@ class BaseAgent:
|
|
|
56
59
|
prompt_dir: Optional[Path] = None,
|
|
57
60
|
default_model: Optional[str] = None,
|
|
58
61
|
) -> None:
|
|
59
|
-
"""Initialize the ``
|
|
62
|
+
"""Initialize the ``AgentBase`` using a configuration object.
|
|
60
63
|
|
|
61
64
|
Parameters
|
|
62
65
|
----------
|
|
@@ -88,10 +91,14 @@ class BaseAgent:
|
|
|
88
91
|
else:
|
|
89
92
|
prompt_path = None
|
|
90
93
|
|
|
91
|
-
if prompt_path is
|
|
94
|
+
if prompt_path is None:
|
|
95
|
+
self._template = Template("")
|
|
96
|
+
elif prompt_path.exists():
|
|
92
97
|
self._template = Template(prompt_path.read_text())
|
|
93
98
|
else:
|
|
94
|
-
|
|
99
|
+
raise FileNotFoundError(
|
|
100
|
+
f"Prompt template for agent '{name}' not found at {prompt_path}."
|
|
101
|
+
)
|
|
95
102
|
|
|
96
103
|
self.agent_name = name
|
|
97
104
|
self.description = description
|
|
@@ -110,8 +117,8 @@ class BaseAgent:
|
|
|
110
117
|
run_context_wrapper: Optional[RunContextWrapper[Dict[str, Any]]] = None,
|
|
111
118
|
prompt_dir: Optional[Path] = None,
|
|
112
119
|
default_model: Optional[str] = None,
|
|
113
|
-
) -> "
|
|
114
|
-
"""Create a :class:`
|
|
120
|
+
) -> "AgentBase":
|
|
121
|
+
"""Create a :class:`AgentBase` instance from configuration.
|
|
115
122
|
|
|
116
123
|
Parameters
|
|
117
124
|
----------
|
|
@@ -126,7 +133,7 @@ class BaseAgent:
|
|
|
126
133
|
|
|
127
134
|
Returns
|
|
128
135
|
-------
|
|
129
|
-
|
|
136
|
+
AgentBase
|
|
130
137
|
Instantiated agent.
|
|
131
138
|
"""
|
|
132
139
|
return cls(
|
|
@@ -136,7 +143,7 @@ class BaseAgent:
|
|
|
136
143
|
default_model=default_model,
|
|
137
144
|
)
|
|
138
145
|
|
|
139
|
-
def
|
|
146
|
+
def _build_prompt_from_jinja(self) -> str:
|
|
140
147
|
"""Return the rendered instructions prompt for this agent.
|
|
141
148
|
|
|
142
149
|
Returns
|
|
@@ -200,7 +207,7 @@ class BaseAgent:
|
|
|
200
207
|
"""
|
|
201
208
|
agent_config: Dict[str, Any] = {
|
|
202
209
|
"name": self.agent_name,
|
|
203
|
-
"instructions": self.
|
|
210
|
+
"instructions": self._build_prompt_from_jinja(),
|
|
204
211
|
"model": self.model,
|
|
205
212
|
}
|
|
206
213
|
if self._output_type:
|
|
@@ -212,19 +219,19 @@ class BaseAgent:
|
|
|
212
219
|
|
|
213
220
|
return Agent(**agent_config)
|
|
214
221
|
|
|
215
|
-
async def
|
|
222
|
+
async def run_async(
|
|
216
223
|
self,
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
input: str,
|
|
225
|
+
context: Optional[Dict[str, Any]] = None,
|
|
219
226
|
output_type: Optional[Any] = None,
|
|
220
227
|
) -> Any:
|
|
221
228
|
"""Execute the agent asynchronously.
|
|
222
229
|
|
|
223
230
|
Parameters
|
|
224
231
|
----------
|
|
225
|
-
|
|
232
|
+
input
|
|
226
233
|
Prompt or query for the agent.
|
|
227
|
-
|
|
234
|
+
context
|
|
228
235
|
Optional dictionary passed to the agent. Default ``None``.
|
|
229
236
|
output_type
|
|
230
237
|
Optional type used to cast the final output. Default ``None``.
|
|
@@ -236,26 +243,26 @@ class BaseAgent:
|
|
|
236
243
|
"""
|
|
237
244
|
if self._output_type is not None and output_type is None:
|
|
238
245
|
output_type = self._output_type
|
|
239
|
-
return await
|
|
246
|
+
return await run_async(
|
|
240
247
|
agent=self.get_agent(),
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
input=input,
|
|
249
|
+
context=context,
|
|
243
250
|
output_type=output_type,
|
|
244
251
|
)
|
|
245
252
|
|
|
246
253
|
def run_sync(
|
|
247
254
|
self,
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
input: str,
|
|
256
|
+
context: Optional[Dict[str, Any]] = None,
|
|
250
257
|
output_type: Optional[Any] = None,
|
|
251
258
|
) -> Any:
|
|
252
259
|
"""Run the agent synchronously.
|
|
253
260
|
|
|
254
261
|
Parameters
|
|
255
262
|
----------
|
|
256
|
-
|
|
263
|
+
input
|
|
257
264
|
Prompt or query for the agent.
|
|
258
|
-
|
|
265
|
+
context
|
|
259
266
|
Optional dictionary passed to the agent. Default ``None``.
|
|
260
267
|
output_type
|
|
261
268
|
Optional type used to cast the final output. Default ``None``.
|
|
@@ -265,30 +272,26 @@ class BaseAgent:
|
|
|
265
272
|
Any
|
|
266
273
|
Agent result, optionally converted to ``output_type``.
|
|
267
274
|
"""
|
|
268
|
-
|
|
269
|
-
self.get_agent(),
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
return run_sync(
|
|
276
|
+
agent=self.get_agent(),
|
|
277
|
+
input=input,
|
|
278
|
+
context=context,
|
|
279
|
+
output_type=output_type,
|
|
272
280
|
)
|
|
273
|
-
if self._output_type and not output_type:
|
|
274
|
-
output_type = self._output_type
|
|
275
|
-
if output_type:
|
|
276
|
-
return result.final_output_as(output_type)
|
|
277
|
-
return result
|
|
278
281
|
|
|
279
282
|
def run_streamed(
|
|
280
283
|
self,
|
|
281
|
-
|
|
282
|
-
|
|
284
|
+
input: str,
|
|
285
|
+
context: Optional[Dict[str, Any]] = None,
|
|
283
286
|
output_type: Optional[Any] = None,
|
|
284
287
|
) -> RunResultStreaming:
|
|
285
288
|
"""Return a streaming result for the agent execution.
|
|
286
289
|
|
|
287
290
|
Parameters
|
|
288
291
|
----------
|
|
289
|
-
|
|
292
|
+
input
|
|
290
293
|
Prompt or query for the agent.
|
|
291
|
-
|
|
294
|
+
context
|
|
292
295
|
Optional dictionary passed to the agent. Default ``None``.
|
|
293
296
|
output_type
|
|
294
297
|
Optional type used to cast the final output. Default ``None``.
|
|
@@ -298,10 +301,10 @@ class BaseAgent:
|
|
|
298
301
|
RunResultStreaming
|
|
299
302
|
Streaming output wrapper from the agent execution.
|
|
300
303
|
"""
|
|
301
|
-
result =
|
|
304
|
+
result = run_streamed(
|
|
302
305
|
agent=self.get_agent(),
|
|
303
|
-
|
|
304
|
-
context=
|
|
306
|
+
input=input,
|
|
307
|
+
context=context,
|
|
305
308
|
)
|
|
306
309
|
if self._output_type and not output_type:
|
|
307
310
|
output_type = self._output_type
|
|
@@ -324,109 +327,4 @@ class BaseAgent:
|
|
|
324
327
|
return tool_obj
|
|
325
328
|
|
|
326
329
|
|
|
327
|
-
|
|
328
|
-
agent: Agent,
|
|
329
|
-
agent_input: str,
|
|
330
|
-
agent_context: Optional[Dict[str, Any]] = None,
|
|
331
|
-
output_type: Optional[Any] = None,
|
|
332
|
-
) -> Any:
|
|
333
|
-
"""Run an ``Agent`` asynchronously.
|
|
334
|
-
|
|
335
|
-
Parameters
|
|
336
|
-
----------
|
|
337
|
-
agent
|
|
338
|
-
Configured agent instance to execute.
|
|
339
|
-
agent_input
|
|
340
|
-
Prompt or query string for the agent.
|
|
341
|
-
agent_context
|
|
342
|
-
Optional context dictionary passed to the agent. Default ``None``.
|
|
343
|
-
output_type
|
|
344
|
-
Optional type used to cast the final output. Default ``None``.
|
|
345
|
-
|
|
346
|
-
Returns
|
|
347
|
-
-------
|
|
348
|
-
Any
|
|
349
|
-
Agent response, optionally converted to ``output_type``.
|
|
350
|
-
"""
|
|
351
|
-
result = await Runner.run(agent, agent_input, context=agent_context)
|
|
352
|
-
if output_type is not None:
|
|
353
|
-
result = result.final_output_as(output_type)
|
|
354
|
-
return result
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
def _run_agent_sync(
|
|
358
|
-
agent: Agent,
|
|
359
|
-
agent_input: str,
|
|
360
|
-
agent_context: Optional[Dict[str, Any]] = None,
|
|
361
|
-
) -> RunResult:
|
|
362
|
-
"""Run an ``Agent`` synchronously.
|
|
363
|
-
|
|
364
|
-
Parameters
|
|
365
|
-
----------
|
|
366
|
-
agent
|
|
367
|
-
Configured agent instance to execute.
|
|
368
|
-
agent_input
|
|
369
|
-
Prompt or query string for the agent.
|
|
370
|
-
agent_context
|
|
371
|
-
Optional context dictionary passed to the agent. Default ``None``.
|
|
372
|
-
|
|
373
|
-
Returns
|
|
374
|
-
-------
|
|
375
|
-
RunResult
|
|
376
|
-
Result from the agent execution.
|
|
377
|
-
"""
|
|
378
|
-
coro = Runner.run(agent, agent_input, context=agent_context)
|
|
379
|
-
try:
|
|
380
|
-
loop = asyncio.get_running_loop()
|
|
381
|
-
except RuntimeError:
|
|
382
|
-
return asyncio.run(coro)
|
|
383
|
-
|
|
384
|
-
if loop.is_running():
|
|
385
|
-
result: RunResult | None = None
|
|
386
|
-
|
|
387
|
-
def _thread_runner() -> None:
|
|
388
|
-
nonlocal result
|
|
389
|
-
result = asyncio.run(coro)
|
|
390
|
-
|
|
391
|
-
thread = threading.Thread(target=_thread_runner, daemon=True)
|
|
392
|
-
thread.start()
|
|
393
|
-
thread.join()
|
|
394
|
-
if result is None:
|
|
395
|
-
raise RuntimeError("Agent execution did not return a result.")
|
|
396
|
-
return result
|
|
397
|
-
|
|
398
|
-
return loop.run_until_complete(coro)
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
def _run_agent_streamed(
|
|
402
|
-
agent: Agent,
|
|
403
|
-
agent_input: str,
|
|
404
|
-
context: Optional[Dict[str, Any]] = None,
|
|
405
|
-
) -> RunResultStreaming:
|
|
406
|
-
"""Run an ``Agent`` synchronously and return a streaming result.
|
|
407
|
-
|
|
408
|
-
Parameters
|
|
409
|
-
----------
|
|
410
|
-
agent
|
|
411
|
-
Configured agent to execute.
|
|
412
|
-
agent_input
|
|
413
|
-
Prompt or query string for the agent.
|
|
414
|
-
context
|
|
415
|
-
Optional context dictionary passed to the agent. Default ``None``.
|
|
416
|
-
|
|
417
|
-
Returns
|
|
418
|
-
-------
|
|
419
|
-
RunResultStreaming
|
|
420
|
-
Instance for streaming outputs.
|
|
421
|
-
"""
|
|
422
|
-
result = Runner.run_streamed(agent, agent_input, context=context)
|
|
423
|
-
return result
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
__all__ = [
|
|
427
|
-
"AgentConfigLike",
|
|
428
|
-
"BaseAgent",
|
|
429
|
-
"_run_agent",
|
|
430
|
-
"_run_agent_sync",
|
|
431
|
-
"_run_agent_streamed",
|
|
432
|
-
]
|
|
330
|
+
__all__ = ["AgentConfigLike", "AgentBase"]
|
{openai_sdk_helpers-0.0.2/src → openai_sdk_helpers-0.0.4}/openai_sdk_helpers/agent/config.py
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Configuration helpers for ``
|
|
1
|
+
"""Configuration helpers for ``AgentBase``."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ from ..structure import BaseStructure
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class AgentConfig(BaseStructure):
|
|
14
|
-
"""Configuration required to build a :class:`
|
|
14
|
+
"""Configuration required to build a :class:`AgentBase`.
|
|
15
15
|
|
|
16
16
|
Methods
|
|
17
17
|
-------
|