openai-sdk-helpers 0.4.3__py3-none-any.whl → 0.5.1__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 (52) hide show
  1. openai_sdk_helpers/__init__.py +41 -7
  2. openai_sdk_helpers/agent/__init__.py +1 -2
  3. openai_sdk_helpers/agent/base.py +169 -190
  4. openai_sdk_helpers/agent/configuration.py +12 -20
  5. openai_sdk_helpers/agent/coordinator.py +14 -17
  6. openai_sdk_helpers/agent/runner.py +3 -45
  7. openai_sdk_helpers/agent/search/base.py +49 -71
  8. openai_sdk_helpers/agent/search/vector.py +82 -110
  9. openai_sdk_helpers/agent/search/web.py +103 -81
  10. openai_sdk_helpers/agent/summarizer.py +20 -28
  11. openai_sdk_helpers/agent/translator.py +17 -23
  12. openai_sdk_helpers/agent/validator.py +17 -23
  13. openai_sdk_helpers/errors.py +9 -0
  14. openai_sdk_helpers/extract/__init__.py +23 -0
  15. openai_sdk_helpers/extract/extractor.py +157 -0
  16. openai_sdk_helpers/extract/generator.py +476 -0
  17. openai_sdk_helpers/files_api.py +1 -0
  18. openai_sdk_helpers/logging.py +12 -1
  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/response/__init__.py +2 -6
  25. openai_sdk_helpers/response/base.py +233 -164
  26. openai_sdk_helpers/response/configuration.py +39 -14
  27. openai_sdk_helpers/response/files.py +41 -2
  28. openai_sdk_helpers/response/runner.py +1 -48
  29. openai_sdk_helpers/response/tool_call.py +0 -141
  30. openai_sdk_helpers/response/vector_store.py +8 -5
  31. openai_sdk_helpers/streamlit_app/app.py +1 -9
  32. openai_sdk_helpers/structure/__init__.py +16 -0
  33. openai_sdk_helpers/structure/base.py +239 -278
  34. openai_sdk_helpers/structure/extraction.py +1228 -0
  35. openai_sdk_helpers/structure/plan/plan.py +0 -20
  36. openai_sdk_helpers/structure/plan/task.py +0 -33
  37. openai_sdk_helpers/structure/prompt.py +16 -0
  38. openai_sdk_helpers/structure/responses.py +2 -2
  39. openai_sdk_helpers/structure/web_search.py +0 -10
  40. openai_sdk_helpers/tools.py +346 -99
  41. openai_sdk_helpers/utils/__init__.py +7 -0
  42. openai_sdk_helpers/utils/json/base_model.py +315 -32
  43. openai_sdk_helpers/utils/langextract.py +194 -0
  44. openai_sdk_helpers/vector_storage/cleanup.py +7 -2
  45. openai_sdk_helpers/vector_storage/storage.py +37 -7
  46. {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.1.dist-info}/METADATA +21 -6
  47. openai_sdk_helpers-0.5.1.dist-info/RECORD +95 -0
  48. openai_sdk_helpers/streamlit_app/streamlit_web_search.py +0 -75
  49. openai_sdk_helpers-0.4.3.dist-info/RECORD +0 -86
  50. {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.1.dist-info}/WHEEL +0 -0
  51. {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.1.dist-info}/entry_points.txt +0 -0
  52. {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.1.dist-info}/licenses/LICENSE +0 -0
@@ -3,13 +3,14 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from pathlib import Path
6
- from typing import Any, Callable, Dict, List, Optional, Union
6
+ from typing import Any, Dict, Optional, Union
7
7
 
8
8
  from agents import custom_span, gen_trace_id, trace
9
9
  from agents.model_settings import ModelSettings
10
10
  from agents.tool import WebSearchTool
11
11
 
12
12
  from ...structure.prompt import PromptStructure
13
+ from ..base import AgentBase
13
14
  from ...structure.web_search import (
14
15
  WebSearchItemStructure,
15
16
  WebSearchItemResultStructure,
@@ -17,10 +18,10 @@ from ...structure.web_search import (
17
18
  WebSearchPlanStructure,
18
19
  WebSearchReportStructure,
19
20
  )
20
- from ...tools import tool_handler_factory
21
21
  from ..configuration import AgentConfiguration
22
22
  from ..utils import run_coroutine_agent_sync
23
23
  from .base import SearchPlanner, SearchToolAgent, SearchWriter
24
+ from ...tools import ToolSpec, ToolHandlerRegistration
24
25
 
25
26
  MAX_CONCURRENT_SEARCHES = 10
26
27
 
@@ -30,10 +31,10 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
30
31
 
31
32
  Parameters
32
33
  ----------
33
- prompt_dir : Path or None, default=None
34
- Directory containing prompt templates.
35
- default_model : str or None, default=None
36
- Default model identifier to use when not defined in configuration.
34
+ template_path : Path | str | None, default=None
35
+ Template file path for prompt rendering.
36
+ model : str | None, default=None
37
+ Model identifier to use when not defined in configuration.
37
38
 
38
39
  Methods
39
40
  -------
@@ -43,20 +44,19 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
43
44
  Raises
44
45
  ------
45
46
  ValueError
46
- If the default model is not provided.
47
+ If the configuration omits a model identifier.
47
48
 
48
49
  Examples
49
50
  --------
50
- >>> planner = WebAgentPlanner(default_model="gpt-4o-mini")
51
+ >>> planner = WebAgentPlanner(model="gpt-4o-mini")
51
52
  """
52
53
 
53
- def __init__(
54
- self, prompt_dir: Optional[Path] = None, default_model: Optional[str] = None
55
- ) -> None:
56
- """Initialize the planner agent."""
57
- super().__init__(prompt_dir=prompt_dir, default_model=default_model)
58
-
59
- def _configure_agent(self) -> AgentConfiguration:
54
+ def _configure_agent(
55
+ self,
56
+ template_path: Path | str | None = None,
57
+ model: str | None = None,
58
+ **kwargs: Any,
59
+ ) -> AgentConfiguration:
60
60
  """Return configuration for the web planner agent.
61
61
 
62
62
  Returns
@@ -68,6 +68,8 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
68
68
  name="web_planner",
69
69
  instructions="Agent instructions",
70
70
  description="Agent that plans web searches based on a user query.",
71
+ template_path=template_path,
72
+ model=model,
71
73
  output_structure=WebSearchPlanStructure,
72
74
  )
73
75
 
@@ -81,10 +83,10 @@ class WebSearchToolAgent(
81
83
 
82
84
  Parameters
83
85
  ----------
84
- prompt_dir : Path or None, default=None
85
- Directory containing prompt templates.
86
- default_model : str or None, default=None
87
- Default model identifier to use when not defined in configuration.
86
+ template_path : Path | str | None, default=None
87
+ Template file path for prompt rendering.
88
+ model : str or None, default=None
89
+ Model identifier to use when not defined in configuration.
88
90
 
89
91
  Methods
90
92
  -------
@@ -96,24 +98,20 @@ class WebSearchToolAgent(
96
98
  Raises
97
99
  ------
98
100
  ValueError
99
- If the default model is not provided.
101
+ If the model is not provided.
100
102
 
101
103
  Examples
102
104
  --------
103
- >>> tool = WebSearchToolAgent(default_model="gpt-4o-mini")
105
+ >>> tool = WebSearchToolAgent(model="gpt-4o-mini")
104
106
  """
105
107
 
106
- def __init__(
107
- self, prompt_dir: Optional[Path] = None, default_model: Optional[str] = None
108
- ) -> None:
109
- """Initialize the search tool agent."""
110
- super().__init__(
111
- prompt_dir=prompt_dir,
112
- default_model=default_model,
113
- max_concurrent_searches=MAX_CONCURRENT_SEARCHES,
114
- )
115
-
116
- def _configure_agent(self) -> AgentConfiguration:
108
+ def _configure_agent(
109
+ self,
110
+ *,
111
+ template_path: Path | str | None = None,
112
+ model: str | None = None,
113
+ **kwargs: Any,
114
+ ) -> AgentConfiguration:
117
115
  """Return configuration for the web search tool agent.
118
116
 
119
117
  Returns
@@ -125,6 +123,8 @@ class WebSearchToolAgent(
125
123
  name="web_search",
126
124
  instructions="Agent instructions",
127
125
  description="Agent that performs web searches and summarizes results.",
126
+ template_path=template_path,
127
+ model=model,
128
128
  input_structure=WebSearchPlanStructure,
129
129
  tools=[WebSearchTool()],
130
130
  model_settings=ModelSettings(tool_choice="required"),
@@ -186,10 +186,10 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
186
186
 
187
187
  Parameters
188
188
  ----------
189
- prompt_dir : Path or None, default=None
190
- Directory containing prompt templates.
191
- default_model : str or None, default=None
192
- Default model identifier to use when not defined in configuration.
189
+ template_path : Path | str | None, default=None
190
+ Template file path for prompt rendering.
191
+ model : str | None, default=None
192
+ Model identifier to use when not defined in configuration.
193
193
 
194
194
  Methods
195
195
  -------
@@ -199,20 +199,31 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
199
199
  Raises
200
200
  ------
201
201
  ValueError
202
- If the default model is not provided.
202
+ If the configuration omits a model identifier.
203
203
 
204
204
  Examples
205
205
  --------
206
- >>> writer = WebAgentWriter(default_model="gpt-4o-mini")
206
+ >>> writer = WebAgentWriter(model="gpt-4o-mini")
207
207
  """
208
208
 
209
209
  def __init__(
210
- self, prompt_dir: Optional[Path] = None, default_model: Optional[str] = None
210
+ self,
211
+ template_path: Path | str | None = None,
212
+ model: str | None = None,
213
+ **kwargs: Any,
211
214
  ) -> None:
212
215
  """Initialize the writer agent."""
213
- super().__init__(prompt_dir=prompt_dir, default_model=default_model)
216
+ configuration = self._configure_agent(
217
+ template_path=template_path, model=model, **kwargs
218
+ )
219
+ super().__init__(configuration=configuration)
214
220
 
215
- def _configure_agent(self) -> AgentConfiguration:
221
+ def _configure_agent(
222
+ self,
223
+ template_path: Path | str | None = None,
224
+ model: str | None = None,
225
+ **kwargs: Any,
226
+ ) -> AgentConfiguration:
216
227
  """Return configuration for the web writer agent.
217
228
 
218
229
  Returns
@@ -224,19 +235,21 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
224
235
  name="web_writer",
225
236
  instructions="Agent instructions",
226
237
  description="Agent that writes a report based on web search results.",
238
+ template_path=template_path,
239
+ model=model,
227
240
  output_structure=WebSearchReportStructure,
228
241
  )
229
242
 
230
243
 
231
- class WebAgentSearch:
244
+ class WebAgentSearch(AgentBase):
232
245
  """Manage the complete web search workflow.
233
246
 
234
247
  Parameters
235
248
  ----------
236
- prompt_dir : Path or None, default=None
237
- Directory containing prompt templates.
238
- default_model : str or None, default=None
239
- Default model identifier to use when not defined in configuration.
249
+ template_path : Path | str | None, default=None
250
+ Template file path for prompt rendering.
251
+ model : str | None, default=None
252
+ Model identifier to use when not defined in configuration.
240
253
 
241
254
  Methods
242
255
  -------
@@ -254,21 +267,36 @@ class WebAgentSearch:
254
267
  Raises
255
268
  ------
256
269
  ValueError
257
- If the default model is not provided.
270
+ If the model identifier is not provided.
258
271
 
259
272
  Examples
260
273
  --------
261
- >>> search = WebAgentSearch(default_model="gpt-4o-mini")
274
+ >>> search = WebAgentSearch(model="gpt-4o-mini")
262
275
  """
263
276
 
264
277
  def __init__(
265
278
  self,
266
- prompt_dir: Optional[Path] = None,
267
- default_model: Optional[str] = None,
279
+ *,
280
+ template_path: Path | str | None = None,
281
+ model: str | None = None,
268
282
  ) -> None:
269
- """Create the main web search agent."""
270
- self._prompt_dir = prompt_dir
271
- self._default_model = default_model
283
+ """Initialize the web search orchestration agent.
284
+
285
+ Parameters
286
+ ----------
287
+ template_path : Path | str | None, default=None
288
+ Optional template file path for prompt rendering.
289
+ model : str | None, default=None
290
+ Model identifier to use when not defined in configuration.
291
+ """
292
+ configuration = AgentConfiguration(
293
+ name="web_agent_search",
294
+ instructions="Agent instructions",
295
+ description="Run a multi-step web search workflow.",
296
+ template_path=template_path,
297
+ model=model,
298
+ )
299
+ super().__init__(configuration=configuration)
272
300
 
273
301
  async def run_agent_async(self, search_query: str) -> WebSearchStructure:
274
302
  """Execute the entire research workflow for ``search_query``.
@@ -286,14 +314,12 @@ class WebAgentSearch:
286
314
  trace_id = gen_trace_id()
287
315
  with trace("WebAgentSearch trace", trace_id=trace_id):
288
316
  planner = WebAgentPlanner(
289
- prompt_dir=self._prompt_dir, default_model=self._default_model
317
+ template_path=self._template_path, model=self.model
290
318
  )
291
319
  tool = WebSearchToolAgent(
292
- prompt_dir=self._prompt_dir, default_model=self._default_model
293
- )
294
- writer = WebAgentWriter(
295
- prompt_dir=self._prompt_dir, default_model=self._default_model
320
+ template_path=self._template_path, model=self.model
296
321
  )
322
+ writer = WebAgentWriter(template_path=self._template_path, model=self.model)
297
323
  search_plan = await planner.run_agent(query=search_query)
298
324
  search_results = await tool.run_agent(search_plan=search_plan)
299
325
  search_report = await writer.run_agent(search_query, search_results)
@@ -320,37 +346,33 @@ class WebAgentSearch:
320
346
  """
321
347
  return run_coroutine_agent_sync(self.run_agent_async(search_query))
322
348
 
323
- def as_response_tool(
324
- self,
325
- *,
326
- tool_name: str = "web_search",
327
- tool_description: str = "Run the web search workflow.",
328
- ) -> tuple[dict[str, Callable[..., Any]], dict[str, Any]]:
329
- """Return a Responses API tool handler and definition.
349
+ def as_tool_registration(
350
+ self, tool_name: str, tool_description: str
351
+ ) -> ToolHandlerRegistration:
352
+ """Build a Responses API tool definition and handler for the web search agent.
330
353
 
331
354
  Parameters
332
355
  ----------
333
- tool_name : str, default="web_search"
334
- Name to use for the response tool.
335
- tool_description : str, default="Run the web search workflow."
336
- Description for the response tool.
356
+ tool_name : str
357
+ Name of the tool.
358
+ tool_description : str
359
+ Description of the tool.
337
360
 
338
361
  Returns
339
362
  -------
340
- tuple[dict[str, Callable[..., Any]], dict[str, Any]]
341
- Tool handler mapping and tool definition for Responses API usage.
363
+ ToolHandlerRegistration
364
+ Tool definition and handler for the Responses API.
342
365
  """
343
-
344
- def _run_search(prompt: str) -> WebSearchStructure:
345
- return run_coroutine_agent_sync(self.run_agent_async(search_query=prompt))
346
-
347
- tool_handler = {
348
- tool_name: tool_handler_factory(_run_search, input_model=PromptStructure)
349
- }
350
- tool_definition = PromptStructure.response_tool_definition(
351
- tool_name, tool_description=tool_description
366
+ tool_spec = ToolSpec(
367
+ input_structure=PromptStructure,
368
+ tool_name=tool_name,
369
+ tool_description=tool_description,
370
+ output_structure=WebSearchStructure,
371
+ )
372
+ return ToolHandlerRegistration(
373
+ handler=self.run_agent_sync,
374
+ tool_spec=tool_spec,
352
375
  )
353
- return tool_handler, tool_definition
354
376
 
355
377
 
356
378
  __all__ = [
@@ -3,13 +3,12 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from pathlib import Path
6
- from typing import Any, Dict, Optional, Type
6
+ from typing import Any, Dict, Optional
7
7
 
8
8
  from ..structure import SummaryStructure
9
9
  from ..structure.base import StructureBase
10
10
  from .base import AgentBase
11
11
  from .configuration import AgentConfiguration
12
- from ..environment import DEFAULT_PROMPT_DIR
13
12
 
14
13
 
15
14
  class SummarizerAgent(AgentBase):
@@ -21,11 +20,10 @@ class SummarizerAgent(AgentBase):
21
20
 
22
21
  Parameters
23
22
  ----------
24
- prompt_dir : Path or None, default=None
25
- Optional directory containing Jinja prompt templates. Defaults to the
26
- packaged ``prompt`` directory when not provided.
27
- default_model : str or None, default=None
28
- Fallback model identifier when not specified elsewhere.
23
+ template_path : Path | str | None, default=None
24
+ Optional template file path for prompt rendering.
25
+ model : str | None, default=None
26
+ Model identifier to use for summarization.
29
27
  output_structure : type[StructureBase], default=SummaryStructure
30
28
  Type describing the expected summary output.
31
29
 
@@ -34,7 +32,7 @@ class SummarizerAgent(AgentBase):
34
32
  Basic usage with default settings:
35
33
 
36
34
  >>> from openai_sdk_helpers.agent import SummarizerAgent
37
- >>> summarizer = SummarizerAgent(default_model="gpt-4o-mini")
35
+ >>> summarizer = SummarizerAgent(model="gpt-4o-mini")
38
36
  >>> summary = summarizer.run_sync("Long text to summarize...")
39
37
  >>> print(summary.text)
40
38
 
@@ -42,7 +40,7 @@ class SummarizerAgent(AgentBase):
42
40
 
43
41
  >>> import asyncio
44
42
  >>> async def main():
45
- ... summarizer = SummarizerAgent(default_model="gpt-4o-mini")
43
+ ... summarizer = SummarizerAgent(model="gpt-4o-mini")
46
44
  ... result = await summarizer.run_agent(
47
45
  ... text="Article content...",
48
46
  ... metadata={"source": "news.txt", "date": "2025-01-01"}
@@ -59,44 +57,38 @@ class SummarizerAgent(AgentBase):
59
57
  def __init__(
60
58
  self,
61
59
  *,
62
- prompt_dir: Optional[Path] = None,
63
- default_model: Optional[str] = None,
64
- output_structure: Type[StructureBase] = SummaryStructure,
60
+ template_path: Path | str | None = None,
61
+ model: str | None = None,
65
62
  ) -> None:
66
63
  """Initialize the summarizer agent configuration.
67
64
 
68
65
  Parameters
69
66
  ----------
70
- prompt_dir : Path or None, default=None
71
- Optional directory containing Jinja prompt templates. Defaults to the
72
- packaged ``prompt`` directory when not provided.
73
- default_model : str or None, default=None
74
- Fallback model identifier when not specified elsewhere.
75
- output_structure : type[StructureBase], default=SummaryStructure
76
- Type describing the expected summary output.
67
+ template_path : Path | str | None, default=None
68
+ Optional template file path for prompt rendering.
69
+ model : str | None, default=None
70
+ Model identifier to use for summarization.
77
71
 
78
72
  Raises
79
73
  ------
80
74
  ValueError
81
- If the default model is not provided.
75
+ If the model is not provided.
82
76
 
83
77
  Examples
84
78
  --------
85
- >>> summarizer = SummarizerAgent(default_model="gpt-4o-mini")
79
+ >>> summarizer = SummarizerAgent(model="gpt-4o-mini")
86
80
  """
87
81
  configuration = AgentConfiguration(
88
82
  name="summarizer",
89
83
  instructions="Agent instructions",
90
84
  description="Summarize passages into concise findings.",
91
- output_structure=output_structure,
92
- )
93
- prompt_directory = prompt_dir or DEFAULT_PROMPT_DIR
94
- super().__init__(
95
- configuration=configuration,
96
- prompt_dir=prompt_directory,
97
- default_model=default_model,
85
+ template_path=template_path,
86
+ output_structure=SummaryStructure,
87
+ model=model,
98
88
  )
99
89
 
90
+ super().__init__(configuration=configuration)
91
+
100
92
  async def run_agent(
101
93
  self, text: str, metadata: Optional[Dict[str, Any]] = None
102
94
  ) -> Any:
@@ -8,7 +8,6 @@ from typing import Any, Dict, Optional
8
8
 
9
9
  from ..structure import TranslationStructure
10
10
  from ..structure.base import StructureBase
11
- from ..environment import DEFAULT_PROMPT_DIR
12
11
 
13
12
  from .base import AgentBase
14
13
  from .configuration import AgentConfiguration
@@ -22,18 +21,17 @@ class TranslatorAgent(AgentBase):
22
21
 
23
22
  Parameters
24
23
  ----------
25
- prompt_dir : Path or None, default=None
26
- Optional directory containing Jinja prompt templates. Defaults to the
27
- packaged ``prompt`` directory when not provided.
28
- default_model : str or None, default=None
29
- Fallback model identifier when not specified elsewhere.
24
+ template_path : Path | str | None, default=None
25
+ Optional template file path for prompt rendering.
26
+ model : str | None, default=None
27
+ Model identifier to use for translation.
30
28
 
31
29
  Examples
32
30
  --------
33
31
  Basic translation:
34
32
 
35
33
  >>> from openai_sdk_helpers.agent import TranslatorAgent
36
- >>> translator = TranslatorAgent(default_model="gpt-4o-mini")
34
+ >>> translator = TranslatorAgent(model="gpt-4o-mini")
37
35
  >>> result = translator.run_sync("Hello world", target_language="Spanish")
38
36
  >>> print(result.text)
39
37
  'Hola mundo'
@@ -42,7 +40,7 @@ class TranslatorAgent(AgentBase):
42
40
 
43
41
  >>> import asyncio
44
42
  >>> async def main():
45
- ... translator = TranslatorAgent(default_model="gpt-4o-mini")
43
+ ... translator = TranslatorAgent(model="gpt-4o-mini")
46
44
  ... result = await translator.run_agent(
47
45
  ... text="Good morning",
48
46
  ... target_language="French",
@@ -62,40 +60,36 @@ class TranslatorAgent(AgentBase):
62
60
  def __init__(
63
61
  self,
64
62
  *,
65
- prompt_dir: Optional[Path] = None,
66
- default_model: Optional[str] = None,
63
+ template_path: Path | str | None = None,
64
+ model: str | None = None,
67
65
  ) -> None:
68
66
  """Initialize the translation agent configuration.
69
67
 
70
68
  Parameters
71
69
  ----------
72
- prompt_dir : Path or None, default=None
73
- Optional directory containing Jinja prompt templates. Defaults to the
74
- packaged ``prompt`` directory when not provided.
75
- default_model : str or None, default=None
76
- Fallback model identifier when not specified elsewhere.
70
+ template_path : Path | str | None, default=None
71
+ Optional template file path for prompt rendering.
72
+ model : str | None, default=None
73
+ Model identifier to use for translation.
77
74
 
78
75
  Raises
79
76
  ------
80
77
  ValueError
81
- If the default model is not provided.
78
+ If the model is not provided.
82
79
 
83
80
  Examples
84
81
  --------
85
- >>> translator = TranslatorAgent(default_model="gpt-4o-mini")
82
+ >>> translator = TranslatorAgent(model="gpt-4o-mini")
86
83
  """
87
84
  configuration = AgentConfiguration(
88
85
  name="translator",
89
86
  instructions="Agent instructions",
90
87
  description="Translate text into the requested language.",
88
+ template_path=template_path,
91
89
  output_structure=TranslationStructure,
90
+ model=model,
92
91
  )
93
- prompt_directory = prompt_dir or DEFAULT_PROMPT_DIR
94
- super().__init__(
95
- configuration=configuration,
96
- prompt_dir=prompt_directory,
97
- default_model=default_model,
98
- )
92
+ super().__init__(configuration=configuration)
99
93
 
100
94
  async def run_agent(
101
95
  self,
@@ -5,7 +5,6 @@ from __future__ import annotations
5
5
  from pathlib import Path
6
6
  from typing import Any, Dict, Optional
7
7
 
8
- from ..environment import DEFAULT_PROMPT_DIR
9
8
  from ..structure.validation import ValidationResultStructure
10
9
  from .base import AgentBase
11
10
  from .configuration import AgentConfiguration
@@ -20,18 +19,17 @@ class ValidatorAgent(AgentBase):
20
19
 
21
20
  Parameters
22
21
  ----------
23
- prompt_dir : Path or None, default=None
24
- Optional directory containing Jinja prompt templates. Defaults to the
25
- packaged ``prompt`` directory when not provided.
26
- default_model : str or None, default=None
27
- Fallback model identifier when not specified elsewhere.
22
+ template_path : Path | str | None, default=None
23
+ Optional template file path for prompt rendering.
24
+ model : str | None, default=None
25
+ Model identifier to use for validation.
28
26
 
29
27
  Examples
30
28
  --------
31
29
  Validate user input:
32
30
 
33
31
  >>> from openai_sdk_helpers.agent import ValidatorAgent
34
- >>> validator = ValidatorAgent(default_model="gpt-4o-mini")
32
+ >>> validator = ValidatorAgent(model="gpt-4o-mini")
35
33
  >>> result = validator.run_sync("Tell me about Python programming")
36
34
  >>> print(result.input_safe) # True
37
35
  >>> print(result.violations) # []
@@ -40,7 +38,7 @@ class ValidatorAgent(AgentBase):
40
38
 
41
39
  >>> import asyncio
42
40
  >>> async def main():
43
- ... validator = ValidatorAgent(default_model="gpt-4o-mini")
41
+ ... validator = ValidatorAgent(model="gpt-4o-mini")
44
42
  ... result = await validator.run_agent(
45
43
  ... user_input="Summarize this document",
46
44
  ... agent_output="Summary containing PII...",
@@ -59,40 +57,36 @@ class ValidatorAgent(AgentBase):
59
57
  def __init__(
60
58
  self,
61
59
  *,
62
- prompt_dir: Optional[Path] = None,
63
- default_model: Optional[str] = None,
60
+ template_path: Path | str | None = None,
61
+ model: str | None = None,
64
62
  ) -> None:
65
63
  """Initialize the validator agent configuration.
66
64
 
67
65
  Parameters
68
66
  ----------
69
- prompt_dir : Path or None, default=None
70
- Optional directory containing Jinja prompt templates. Defaults to the
71
- packaged ``prompt`` directory when not provided.
72
- default_model : str or None, default=None
73
- Fallback model identifier when not specified elsewhere.
67
+ template_path : Path | str | None, default=None
68
+ Optional template file path for prompt rendering.
69
+ model : str | None, default=None
70
+ Model identifier to use for validation.
74
71
 
75
72
  Raises
76
73
  ------
77
74
  ValueError
78
- If the default model is not provided.
75
+ If the model is not provided.
79
76
 
80
77
  Examples
81
78
  --------
82
- >>> validator = ValidatorAgent(default_model="gpt-4o-mini")
79
+ >>> validator = ValidatorAgent(model="gpt-4o-mini")
83
80
  """
84
81
  configuration = AgentConfiguration(
85
82
  name="validator",
86
83
  instructions="Agent instructions",
87
84
  description="Validate user input and agent output against guardrails.",
85
+ template_path=template_path,
88
86
  output_structure=ValidationResultStructure,
87
+ model=model,
89
88
  )
90
- prompt_directory = prompt_dir or DEFAULT_PROMPT_DIR
91
- super().__init__(
92
- configuration=configuration,
93
- prompt_dir=prompt_directory,
94
- default_model=default_model,
95
- )
89
+ super().__init__(configuration=configuration)
96
90
 
97
91
  async def run_agent(
98
92
  self,
@@ -119,3 +119,12 @@ class ResourceCleanupError(OpenAISDKError):
119
119
  """
120
120
 
121
121
  pass
122
+
123
+
124
+ class ExtractionError(OpenAISDKError):
125
+ """Extraction execution failed.
126
+
127
+ Raised when LangExtract operations fail or output validation fails.
128
+ """
129
+
130
+ pass
@@ -0,0 +1,23 @@
1
+ """LangExtract-powered document extraction helpers."""
2
+
3
+ from .extractor import DocumentExtractor
4
+ from .generator import (
5
+ EXTRACTOR_CONFIG_GENERATOR,
6
+ EXTRACTOR_CONFIG_AGENT_INSTRUCTIONS,
7
+ PROMPT_OPTIMIZER_AGENT_INSTRUCTIONS,
8
+ generate_document_extractor_config,
9
+ generate_document_extractor_config_with_agent,
10
+ optimize_extractor_prompt,
11
+ optimize_extractor_prompt_with_agent,
12
+ )
13
+
14
+ __all__ = [
15
+ "DocumentExtractor",
16
+ "EXTRACTOR_CONFIG_GENERATOR",
17
+ "EXTRACTOR_CONFIG_AGENT_INSTRUCTIONS",
18
+ "PROMPT_OPTIMIZER_AGENT_INSTRUCTIONS",
19
+ "generate_document_extractor_config",
20
+ "generate_document_extractor_config_with_agent",
21
+ "optimize_extractor_prompt",
22
+ "optimize_extractor_prompt_with_agent",
23
+ ]