StructuredAgent
Base classes¶
Name | Children | Inherits |
---|---|---|
Generic typing Abstract base class for generic types. |
⋔ Inheritance diagram¶
graph TD
94350421494496["structured.StructuredAgent"]
94350360566400["typing.Generic"]
140709601677504["builtins.object"]
94350360566400 --> 94350421494496
140709601677504 --> 94350360566400
🛈 DocStrings¶
Wrapper for Agent that enforces a specific result type.
This wrapper ensures the agent always returns results of the specified type. The type can be provided as: - A Python type for validation - A response definition name from the manifest - A complete response definition instance
Source code in src/llmling_agent/agent/structured.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
__aenter__
async
¶
__aenter__() -> Self
Enter async context and set up MCP servers.
Called when agent enters its async context. Sets up any configured MCP servers and their tools.
Source code in src/llmling_agent/agent/structured.py
86 87 88 89 90 91 92 93 |
|
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
)
Exit async context.
Source code in src/llmling_agent/agent/structured.py
95 96 97 98 99 100 101 102 |
|
__init__
¶
__init__(
agent: AnyAgent[TDeps, TResult],
result_type: type[TResult] | str | ResponseDefinition,
*,
tool_name: str | None = None,
tool_description: str | None = None,
)
Initialize structured agent wrapper.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
AnyAgent[TDeps, TResult]
|
Base agent to wrap |
required |
result_type
|
type[TResult] | str | ResponseDefinition
|
Expected result type: - BaseModel / dataclasses - Name of response definition in manifest - Complete response definition instance |
required |
tool_name
|
str | None
|
Optional override for tool name |
None
|
tool_description
|
str | None
|
Optional override for tool description |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If named response type not found in manifest |
Source code in src/llmling_agent/agent/structured.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
run
async
¶
run(
*prompt: AnyPromptType | TResult,
result_type: type[TResult] | None = None,
deps: TDeps | None = None,
model: ModelType = None,
) -> ChatMessage[TResult]
Run with fixed result type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
AnyPromptType | TResult
|
Any prompt-compatible object or structured objects of type TResult |
()
|
result_type
|
type[TResult] | None
|
Expected result type: - BaseModel / dataclasses - Name of response definition in manifest - Complete response definition instance |
None
|
deps
|
TDeps | None
|
Optional dependencies for the agent |
None
|
message_history
|
Optional previous messages for context |
required | |
model
|
ModelType
|
Optional model override |
None
|
usage
|
Optional usage tracking |
required |
Source code in src/llmling_agent/agent/structured.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|