openai-sdk-helpers 0.0.7__py3-none-any.whl → 0.0.9__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 (63) hide show
  1. openai_sdk_helpers/__init__.py +85 -10
  2. openai_sdk_helpers/agent/__init__.py +8 -4
  3. openai_sdk_helpers/agent/base.py +81 -46
  4. openai_sdk_helpers/agent/config.py +6 -4
  5. openai_sdk_helpers/agent/{project_manager.py → coordination.py} +29 -45
  6. openai_sdk_helpers/agent/prompt_utils.py +7 -1
  7. openai_sdk_helpers/agent/runner.py +67 -141
  8. openai_sdk_helpers/agent/search/__init__.py +33 -0
  9. openai_sdk_helpers/agent/search/base.py +297 -0
  10. openai_sdk_helpers/agent/{vector_search.py → search/vector.py} +89 -157
  11. openai_sdk_helpers/agent/{web_search.py → search/web.py} +82 -162
  12. openai_sdk_helpers/agent/summarizer.py +29 -8
  13. openai_sdk_helpers/agent/translator.py +40 -13
  14. openai_sdk_helpers/agent/validation.py +32 -8
  15. openai_sdk_helpers/async_utils.py +132 -0
  16. openai_sdk_helpers/config.py +74 -36
  17. openai_sdk_helpers/context_manager.py +241 -0
  18. openai_sdk_helpers/enums/__init__.py +9 -1
  19. openai_sdk_helpers/enums/base.py +67 -8
  20. openai_sdk_helpers/environment.py +33 -6
  21. openai_sdk_helpers/errors.py +133 -0
  22. openai_sdk_helpers/logging_config.py +105 -0
  23. openai_sdk_helpers/prompt/__init__.py +10 -71
  24. openai_sdk_helpers/prompt/base.py +172 -0
  25. openai_sdk_helpers/response/__init__.py +37 -5
  26. openai_sdk_helpers/response/base.py +427 -189
  27. openai_sdk_helpers/response/config.py +176 -0
  28. openai_sdk_helpers/response/messages.py +104 -40
  29. openai_sdk_helpers/response/runner.py +79 -35
  30. openai_sdk_helpers/response/tool_call.py +75 -12
  31. openai_sdk_helpers/response/vector_store.py +29 -16
  32. openai_sdk_helpers/retry.py +175 -0
  33. openai_sdk_helpers/streamlit_app/__init__.py +30 -0
  34. openai_sdk_helpers/streamlit_app/app.py +345 -0
  35. openai_sdk_helpers/streamlit_app/config.py +502 -0
  36. openai_sdk_helpers/streamlit_app/streamlit_web_search.py +68 -0
  37. openai_sdk_helpers/structure/__init__.py +69 -3
  38. openai_sdk_helpers/structure/agent_blueprint.py +82 -19
  39. openai_sdk_helpers/structure/base.py +245 -91
  40. openai_sdk_helpers/structure/plan/__init__.py +15 -1
  41. openai_sdk_helpers/structure/plan/enum.py +41 -5
  42. openai_sdk_helpers/structure/plan/plan.py +101 -45
  43. openai_sdk_helpers/structure/plan/task.py +38 -6
  44. openai_sdk_helpers/structure/prompt.py +21 -2
  45. openai_sdk_helpers/structure/responses.py +52 -11
  46. openai_sdk_helpers/structure/summary.py +55 -7
  47. openai_sdk_helpers/structure/validation.py +34 -6
  48. openai_sdk_helpers/structure/vector_search.py +132 -18
  49. openai_sdk_helpers/structure/web_search.py +128 -12
  50. openai_sdk_helpers/types.py +57 -0
  51. openai_sdk_helpers/utils/__init__.py +32 -1
  52. openai_sdk_helpers/utils/core.py +200 -32
  53. openai_sdk_helpers/validation.py +302 -0
  54. openai_sdk_helpers/vector_storage/__init__.py +21 -1
  55. openai_sdk_helpers/vector_storage/cleanup.py +25 -13
  56. openai_sdk_helpers/vector_storage/storage.py +124 -66
  57. openai_sdk_helpers/vector_storage/types.py +20 -19
  58. openai_sdk_helpers-0.0.9.dist-info/METADATA +550 -0
  59. openai_sdk_helpers-0.0.9.dist-info/RECORD +66 -0
  60. openai_sdk_helpers-0.0.7.dist-info/METADATA +0 -193
  61. openai_sdk_helpers-0.0.7.dist-info/RECORD +0 -51
  62. {openai_sdk_helpers-0.0.7.dist-info → openai_sdk_helpers-0.0.9.dist-info}/WHEEL +0 -0
  63. {openai_sdk_helpers-0.0.7.dist-info → openai_sdk_helpers-0.0.9.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,8 @@
1
- """Structured output model for agent plans."""
1
+ """Structured output model for agent plans.
2
+
3
+ This module defines a Pydantic model for representing ordered lists of agent
4
+ tasks, with support for sequential execution and result aggregation.
5
+ """
2
6
 
3
7
  from __future__ import annotations
4
8
 
@@ -6,7 +10,8 @@ import asyncio
6
10
  import inspect
7
11
  import threading
8
12
  from datetime import datetime, timezone
9
- from typing import Any, Callable, Dict, List, Mapping
13
+ from typing import Any, Awaitable, Callable, Coroutine, cast
14
+ from collections.abc import Mapping
10
15
 
11
16
  from .enum import AgentEnum
12
17
  from ..base import BaseStructure, spec_field
@@ -16,6 +21,14 @@ from .task import TaskStructure
16
21
  class PlanStructure(BaseStructure):
17
22
  """Structured representation of an ordered list of agent tasks.
18
23
 
24
+ Represents a complete execution plan consisting of multiple agent tasks
25
+ to be run sequentially, with support for context passing between tasks.
26
+
27
+ Attributes
28
+ ----------
29
+ tasks : list[TaskStructure]
30
+ Ordered list of agent tasks to execute.
31
+
19
32
  Methods
20
33
  -------
21
34
  print()
@@ -23,12 +36,21 @@ class PlanStructure(BaseStructure):
23
36
  __len__()
24
37
  Return the count of tasks in the plan.
25
38
  append(task)
26
- Append an ``TaskStructure`` to the plan.
39
+ Append a TaskStructure to the plan.
27
40
  execute(agent_registry, halt_on_error)
28
41
  Run tasks sequentially using the provided agent callables.
42
+
43
+ Examples
44
+ --------
45
+ >>> plan = PlanStructure(tasks=[
46
+ ... TaskStructure(prompt="Task 1"),
47
+ ... TaskStructure(prompt="Task 2")
48
+ ... ])
49
+ >>> len(plan)
50
+ 2
29
51
  """
30
52
 
31
- tasks: List[TaskStructure] = spec_field(
53
+ tasks: list[TaskStructure] = spec_field(
32
54
  "tasks",
33
55
  default_factory=list,
34
56
  description="Ordered list of agent tasks to execute.",
@@ -37,22 +59,15 @@ class PlanStructure(BaseStructure):
37
59
  def print(self) -> str:
38
60
  """Return a human-readable representation of the plan.
39
61
 
40
- Parameters
41
- ----------
42
- None
43
-
44
62
  Returns
45
63
  -------
46
64
  str
47
- Concatenated description of each plan step.
48
-
49
- Raises
50
- ------
51
- None
65
+ Concatenated description of each task with task numbers.
52
66
 
53
67
  Examples
54
68
  --------
55
- >>> PlanStructure().print()
69
+ >>> plan = PlanStructure()
70
+ >>> plan.print()
56
71
  'No tasks defined.'
57
72
  """
58
73
  if not self.tasks:
@@ -62,21 +77,13 @@ class PlanStructure(BaseStructure):
62
77
  )
63
78
 
64
79
  def __len__(self) -> int:
65
- """Return the number of tasks contained in the plan.
66
-
67
- Parameters
68
- ----------
69
- None
80
+ """Return the number of tasks in the plan.
70
81
 
71
82
  Returns
72
83
  -------
73
84
  int
74
85
  Count of stored agent tasks.
75
86
 
76
- Raises
77
- ------
78
- None
79
-
80
87
  Examples
81
88
  --------
82
89
  >>> len(PlanStructure())
@@ -92,14 +99,6 @@ class PlanStructure(BaseStructure):
92
99
  task : TaskStructure
93
100
  Task to append to the plan.
94
101
 
95
- Returns
96
- -------
97
- None
98
-
99
- Raises
100
- ------
101
- None
102
-
103
102
  Examples
104
103
  --------
105
104
  >>> plan = PlanStructure()
@@ -109,18 +108,23 @@ class PlanStructure(BaseStructure):
109
108
 
110
109
  def execute(
111
110
  self,
112
- agent_registry: Mapping[AgentEnum | str, Callable[..., Any]],
111
+ agent_registry: Mapping[
112
+ AgentEnum | str, Callable[..., object | Coroutine[Any, Any, object]]
113
+ ],
113
114
  *,
114
115
  halt_on_error: bool = True,
115
116
  ) -> list[str]:
116
117
  """Execute tasks with registered agent callables and record outputs.
117
118
 
119
+ Runs each task in sequence, passing results as context to subsequent
120
+ tasks. Updates task status, timing, and results as execution proceeds.
121
+
118
122
  Parameters
119
123
  ----------
120
124
  agent_registry : Mapping[AgentEnum | str, Callable[..., Any]]
121
- Lookup of agent identifiers to callables. Keys may be ``AgentEnum``
125
+ Lookup of agent identifiers to callables. Keys may be AgentEnum
122
126
  instances or their string values. Each callable receives the task
123
- prompt (augmented with prior context) and an optional ``context``
127
+ prompt (augmented with prior context) and an optional context
124
128
  keyword containing accumulated results.
125
129
  halt_on_error : bool, default=True
126
130
  Whether execution should stop when a task raises an exception.
@@ -133,8 +137,15 @@ class PlanStructure(BaseStructure):
133
137
  Raises
134
138
  ------
135
139
  KeyError
136
- If a task does not have a corresponding callable in
137
- ``agent_registry``.
140
+ If a task does not have a corresponding callable in agent_registry.
141
+
142
+ Examples
143
+ --------
144
+ >>> def agent_fn(prompt, context=None):
145
+ ... return f"Result for {prompt}"
146
+ >>> registry = {AgentEnum.WEB_SEARCH: agent_fn}
147
+ >>> plan = PlanStructure(tasks=[TaskStructure(prompt="Test")])
148
+ >>> results = plan.execute(registry) # doctest: +SKIP
138
149
  """
139
150
  aggregated_results: list[str] = []
140
151
  for task in self.tasks:
@@ -171,7 +182,18 @@ class PlanStructure(BaseStructure):
171
182
 
172
183
  @staticmethod
173
184
  def _resolve_registry_key(task_type: AgentEnum | str) -> str:
174
- """Return a normalized registry key for the given ``task_type``."""
185
+ """Return a normalized registry key for the given task_type.
186
+
187
+ Parameters
188
+ ----------
189
+ task_type : AgentEnum | str
190
+ Task type to normalize.
191
+
192
+ Returns
193
+ -------
194
+ str
195
+ Normalized key for agent registry lookup.
196
+ """
175
197
  if isinstance(task_type, AgentEnum):
176
198
  return task_type.value
177
199
  if task_type in AgentEnum.__members__:
@@ -185,11 +207,14 @@ class PlanStructure(BaseStructure):
185
207
  def _run_task(
186
208
  task: TaskStructure,
187
209
  *,
188
- agent_callable: Callable[..., Any],
210
+ agent_callable: Callable[..., object | Coroutine[Any, Any, object]],
189
211
  aggregated_context: list[str],
190
- ) -> Any:
212
+ ) -> object | Coroutine[Any, Any, object]:
191
213
  """Execute a single task using the supplied callable.
192
214
 
215
+ Combines task context with aggregated results from previous tasks,
216
+ then invokes the agent callable with the augmented prompt.
217
+
193
218
  Parameters
194
219
  ----------
195
220
  task : TaskStructure
@@ -218,26 +243,57 @@ class PlanStructure(BaseStructure):
218
243
  return agent_callable(prompt_with_context)
219
244
 
220
245
  @staticmethod
221
- def _normalize_results(result: Any) -> list[str]:
222
- """Convert callable outputs into a list of strings."""
246
+ def _normalize_results(result: object | Coroutine[Any, Any, object]) -> list[str]:
247
+ """Convert callable outputs into a list of strings.
248
+
249
+ Handles various result types including None, awaitables, lists,
250
+ and single values.
251
+
252
+ Parameters
253
+ ----------
254
+ result : Any
255
+ Raw result from agent callable.
256
+
257
+ Returns
258
+ -------
259
+ list[str]
260
+ Normalized list of string results.
261
+ """
223
262
  if result is None:
224
263
  return []
225
264
  if inspect.isawaitable(result):
226
- return PlanStructure._normalize_results(PlanStructure._await_result(result))
265
+ awaited = PlanStructure._await_result(
266
+ cast(Coroutine[Any, Any, object], result)
267
+ )
268
+ return PlanStructure._normalize_results(awaited)
227
269
  if isinstance(result, list):
228
270
  return [str(item) for item in result]
229
271
  return [str(result)]
230
272
 
231
273
  @staticmethod
232
- def _await_result(result: Any) -> Any:
233
- """Await the provided result, handling running event loops."""
274
+ def _await_result(result: Coroutine[Any, Any, object]) -> object:
275
+ """Await the provided result, handling running event loops.
276
+
277
+ Properly handles awaiting results whether an event loop is running
278
+ or not, using a separate thread when necessary.
279
+
280
+ Parameters
281
+ ----------
282
+ result : Any
283
+ Awaitable result to resolve.
284
+
285
+ Returns
286
+ -------
287
+ Any
288
+ Resolved value from the awaitable.
289
+ """
234
290
  try:
235
291
  loop = asyncio.get_running_loop()
236
292
  except RuntimeError:
237
293
  return asyncio.run(result)
238
294
 
239
295
  if loop.is_running():
240
- container: Dict[str, Any] = {"value": None}
296
+ container: dict[str, object | None] = {"value": None}
241
297
 
242
298
  def _runner() -> None:
243
299
  container["value"] = asyncio.run(result)
@@ -1,9 +1,13 @@
1
- """Structured output model for agent tasks."""
1
+ """Structured output model for agent tasks.
2
+
3
+ This module defines a Pydantic model for representing individual agent tasks
4
+ within a plan, including task type, inputs, status tracking, and results.
5
+ """
2
6
 
3
7
  from __future__ import annotations
4
8
 
5
9
  from datetime import datetime
6
- from typing import List, Literal, Optional
10
+ from typing import Literal
7
11
 
8
12
  from pydantic import field_validator
9
13
 
@@ -14,10 +18,38 @@ from ..base import BaseStructure, spec_field
14
18
  class TaskStructure(BaseStructure):
15
19
  """Structured representation of a single agent task.
16
20
 
21
+ Represents one task in an agent execution plan, including its type,
22
+ inputs, execution status, timing, and results.
23
+
24
+ Attributes
25
+ ----------
26
+ task_type : AgentEnum
27
+ Agent type responsible for executing the task.
28
+ prompt : str
29
+ Input passed to the agent.
30
+ context : list[str] or None
31
+ Additional context forwarded to the agent callable.
32
+ start_date : datetime or None
33
+ Timestamp marking when the task started (UTC).
34
+ end_date : datetime or None
35
+ Timestamp marking when the task completed (UTC).
36
+ status : Literal["waiting", "running", "done", "error"]
37
+ Current lifecycle state for the task.
38
+ results : list[str]
39
+ Normalized string outputs returned by the agent.
40
+
17
41
  Methods
18
42
  -------
19
43
  print()
20
44
  Return a formatted multi-line description of the task.
45
+
46
+ Examples
47
+ --------
48
+ >>> task = TaskStructure(
49
+ ... task_type=AgentEnum.WEB_SEARCH,
50
+ ... prompt="Research AI trends",
51
+ ... status="waiting"
52
+ ... )
21
53
  """
22
54
 
23
55
  task_type: AgentEnum = spec_field(
@@ -30,17 +62,17 @@ class TaskStructure(BaseStructure):
30
62
  description="Input passed to the agent.",
31
63
  examples=["Research the latest trends in AI-assisted data analysis."],
32
64
  )
33
- context: List[str] | None = spec_field(
65
+ context: list[str] | None = spec_field(
34
66
  "context",
35
67
  default_factory=list,
36
68
  description="Additional context forwarded to the agent callable.",
37
69
  )
38
- start_date: Optional[datetime] = spec_field(
70
+ start_date: datetime | None = spec_field(
39
71
  "start_date",
40
72
  default=None,
41
73
  description="Timestamp marking when the task started (UTC).",
42
74
  )
43
- end_date: Optional[datetime] = spec_field(
75
+ end_date: datetime | None = spec_field(
44
76
  "end_date",
45
77
  default=None,
46
78
  description="Timestamp marking when the task completed (UTC).",
@@ -50,7 +82,7 @@ class TaskStructure(BaseStructure):
50
82
  default="waiting",
51
83
  description="Current lifecycle state for the task.",
52
84
  )
53
- results: List[str] = spec_field(
85
+ results: list[str] = spec_field(
54
86
  "results",
55
87
  default_factory=list,
56
88
  description="Normalized string outputs returned by the agent.",
@@ -1,4 +1,8 @@
1
- """Shared structured output model for prompts."""
1
+ """Structured output model for prompts.
2
+
3
+ This module defines a simple Pydantic model for representing prompt text
4
+ used in OpenAI API requests.
5
+ """
2
6
 
3
7
  from __future__ import annotations
4
8
 
@@ -6,12 +10,27 @@ from .base import BaseStructure, spec_field
6
10
 
7
11
 
8
12
  class PromptStructure(BaseStructure):
9
- """The prompt text to use for the OpenAI API request.
13
+ """Structured representation of prompt text for OpenAI API requests.
14
+
15
+ Simple structure containing a single prompt string with examples.
16
+
17
+ Attributes
18
+ ----------
19
+ prompt : str
20
+ The prompt text to use for the OpenAI API request.
10
21
 
11
22
  Methods
12
23
  -------
13
24
  print()
14
25
  Return the formatted model fields.
26
+
27
+ Examples
28
+ --------
29
+ >>> prompt_struct = PromptStructure(
30
+ ... prompt="What is the capital of France?"
31
+ ... )
32
+ >>> print(prompt_struct.prompt)
33
+ 'What is the capital of France?'
15
34
  """
16
35
 
17
36
  prompt: str = spec_field(
@@ -1,8 +1,12 @@
1
- """OpenAI response and tool helpers for structured outputs."""
1
+ """OpenAI response and tool helpers for structured outputs.
2
2
 
3
- from __future__ import annotations
3
+ This module provides helper functions for creating OpenAI API response formats
4
+ and tool definitions from BaseStructure classes. These helpers simplify the
5
+ process of configuring structured outputs for both Assistant and chat
6
+ completion APIs.
7
+ """
4
8
 
5
- from typing import Type
9
+ from __future__ import annotations
6
10
 
7
11
  from openai.types.responses.response_format_text_json_schema_config_param import (
8
12
  ResponseFormatTextJSONSchemaConfigParam,
@@ -14,10 +18,13 @@ from ..utils import log
14
18
 
15
19
 
16
20
  def assistant_tool_definition(
17
- structure: Type[BaseStructure], name: str, description: str
21
+ structure: type[BaseStructure], name: str, description: str
18
22
  ) -> dict:
19
23
  """Build a function tool definition for OpenAI Assistants.
20
24
 
25
+ Creates a tool definition compatible with the Assistant API that uses
26
+ the structure's schema as function parameters.
27
+
21
28
  Parameters
22
29
  ----------
23
30
  structure : type[BaseStructure]
@@ -30,7 +37,16 @@ def assistant_tool_definition(
30
37
  Returns
31
38
  -------
32
39
  dict
33
- Assistant tool definition payload.
40
+ Assistant tool definition payload in OpenAI format.
41
+
42
+ Examples
43
+ --------
44
+ >>> from openai_sdk_helpers.structure import BaseStructure
45
+ >>> tool = assistant_tool_definition(
46
+ ... BaseStructure,
47
+ ... "process_data",
48
+ ... "Process input data"
49
+ ... )
34
50
  """
35
51
  log(f"{structure.__name__}::assistant_tool_definition")
36
52
  return {
@@ -43,9 +59,12 @@ def assistant_tool_definition(
43
59
  }
44
60
 
45
61
 
46
- def assistant_format(structure: Type[BaseStructure]) -> dict:
62
+ def assistant_format(structure: type[BaseStructure]) -> dict:
47
63
  """Build a response format definition for OpenAI Assistants.
48
64
 
65
+ Creates a response format specification that instructs the Assistant API
66
+ to return structured output matching the provided schema.
67
+
49
68
  Parameters
50
69
  ----------
51
70
  structure : type[BaseStructure]
@@ -54,7 +73,11 @@ def assistant_format(structure: Type[BaseStructure]) -> dict:
54
73
  Returns
55
74
  -------
56
75
  dict
57
- Assistant response format definition.
76
+ Assistant response format definition in OpenAI format.
77
+
78
+ Examples
79
+ --------
80
+ >>> format_def = assistant_format(BaseStructure)
58
81
  """
59
82
  log(f"{structure.__name__}::assistant_format")
60
83
  return {
@@ -67,12 +90,15 @@ def assistant_format(structure: Type[BaseStructure]) -> dict:
67
90
 
68
91
 
69
92
  def response_tool_definition(
70
- structure: Type[BaseStructure],
93
+ structure: type[BaseStructure],
71
94
  tool_name: str,
72
95
  tool_description: str,
73
96
  ) -> dict:
74
97
  """Build a tool definition for OpenAI chat completions.
75
98
 
99
+ Creates a function tool definition compatible with the chat completions
100
+ API, using the structure's schema as parameters.
101
+
76
102
  Parameters
77
103
  ----------
78
104
  structure : type[BaseStructure]
@@ -85,7 +111,15 @@ def response_tool_definition(
85
111
  Returns
86
112
  -------
87
113
  dict
88
- Tool definition payload for chat completions.
114
+ Tool definition payload for chat completions API.
115
+
116
+ Examples
117
+ --------
118
+ >>> tool = response_tool_definition(
119
+ ... BaseStructure,
120
+ ... "analyze",
121
+ ... "Analyze data"
122
+ ... )
89
123
  """
90
124
  log(f"{structure.__name__}::response_tool_definition")
91
125
  return {
@@ -98,9 +132,12 @@ def response_tool_definition(
98
132
  }
99
133
 
100
134
 
101
- def response_format(structure: Type[BaseStructure]) -> ResponseTextConfigParam:
135
+ def response_format(structure: type[BaseStructure]) -> ResponseTextConfigParam:
102
136
  """Build a response format for OpenAI chat completions.
103
137
 
138
+ Creates a response format specification that instructs the chat
139
+ completions API to return structured output matching the schema.
140
+
104
141
  Parameters
105
142
  ----------
106
143
  structure : type[BaseStructure]
@@ -109,7 +146,11 @@ def response_format(structure: Type[BaseStructure]) -> ResponseTextConfigParam:
109
146
  Returns
110
147
  -------
111
148
  ResponseTextConfigParam
112
- Response format definition.
149
+ Response format definition for chat completions API.
150
+
151
+ Examples
152
+ --------
153
+ >>> format_spec = response_format(BaseStructure)
113
154
  """
114
155
  log(f"{structure.__name__}::response_format")
115
156
  response_format_text_JSONSchema_config_param = (
@@ -1,8 +1,10 @@
1
- """Shared structured output models for summaries."""
1
+ """Structured output models for summaries.
2
2
 
3
- from __future__ import annotations
3
+ This module defines Pydantic models for representing summarization results,
4
+ including topic-level summaries with citations and consolidated text summaries.
5
+ """
4
6
 
5
- from typing import List
7
+ from __future__ import annotations
6
8
 
7
9
  from .base import BaseStructure, spec_field
8
10
 
@@ -10,10 +12,30 @@ from .base import BaseStructure, spec_field
10
12
  class SummaryTopic(BaseStructure):
11
13
  """Capture a topic-level summary with supporting citations.
12
14
 
15
+ Represents a single topic or micro-trend identified in source excerpts,
16
+ along with a summary and supporting citations.
17
+
18
+ Attributes
19
+ ----------
20
+ topic : str
21
+ Topic or micro-trend identified in the provided excerpts.
22
+ summary : str
23
+ Concise explanation of what the excerpts convey about the topic.
24
+ citations : list[str]
25
+ Indices or short quotes that justify the topic summary.
26
+
13
27
  Methods
14
28
  -------
15
29
  print()
16
30
  Return a formatted string representation of the stored fields.
31
+
32
+ Examples
33
+ --------
34
+ >>> topic = SummaryTopic(
35
+ ... topic="AI Trends",
36
+ ... summary="Growing adoption of AI",
37
+ ... citations=["Source 1", "Source 2"]
38
+ ... )
17
39
  """
18
40
 
19
41
  topic: str = spec_field(
@@ -26,7 +48,7 @@ class SummaryTopic(BaseStructure):
26
48
  default=...,
27
49
  description="Concise explanation of what the excerpts convey about the topic.",
28
50
  )
29
- citations: List[str] = spec_field(
51
+ citations: list[str] = spec_field(
30
52
  "citations",
31
53
  default_factory=list,
32
54
  description="Indices or short quotes that justify the topic summary.",
@@ -34,12 +56,23 @@ class SummaryTopic(BaseStructure):
34
56
 
35
57
 
36
58
  class SummaryStructure(BaseStructure):
37
- """Defines the consolidated summary returned by the summarizer agent.
59
+ """Consolidated summary returned by the summarizer agent.
60
+
61
+ Represents a synthesized summary text derived from multiple source excerpts.
62
+
63
+ Attributes
64
+ ----------
65
+ text : str
66
+ Combined summary synthesized from the supplied excerpts.
38
67
 
39
68
  Methods
40
69
  -------
41
70
  print()
42
71
  Return a formatted string representation of the stored fields.
72
+
73
+ Examples
74
+ --------
75
+ >>> summary = SummaryStructure(text="This is a summary")
43
76
  """
44
77
 
45
78
  text: str = spec_field(
@@ -50,15 +83,30 @@ class SummaryStructure(BaseStructure):
50
83
 
51
84
 
52
85
  class ExtendedSummaryStructure(SummaryStructure):
53
- """Extend ``SummaryStructure`` with optional topic breakdown metadata.
86
+ """Extended summary with optional topic breakdown metadata.
87
+
88
+ Extends SummaryStructure to include topic-level summaries with citations,
89
+ providing more granular insight into the summarization.
90
+
91
+ Attributes
92
+ ----------
93
+ metadata : list[SummaryTopic]
94
+ Optional topic-level summaries with supporting citations.
54
95
 
55
96
  Methods
56
97
  -------
57
98
  print()
58
99
  Return a formatted string representation of the stored fields.
100
+
101
+ Examples
102
+ --------
103
+ >>> extended = ExtendedSummaryStructure(
104
+ ... text="Overall summary",
105
+ ... metadata=[SummaryTopic(topic="T1", summary="S1", citations=[])]
106
+ ... )
59
107
  """
60
108
 
61
- metadata: List[SummaryTopic] = spec_field(
109
+ metadata: list[SummaryTopic] = spec_field(
62
110
  "metadata",
63
111
  default_factory=list,
64
112
  description="Optional topic-level summaries with supporting citations.",