Agents module
Agent
An agent is a wrapper around a LLM model that can generate responses to input text.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the agent. |
model |
str
|
The LLM model that the agent will use. Models follow the format of
" |
response_format |
type[BaseModel] | None
|
The Pydantic model that the response will be validated against. |
parameters |
dict[str, Any]
|
A dictionary of parameters that the model will use. These parameters are specific to the model. Examples: {"temperature": 0.5} {"max_tokens": 100} |
tools |
list[Tool]
|
The tools exposed to the agent. |
mcp |
list[MCPEndpoint]
|
The MCP endpoints that the agent can invoke. |
hooks |
AgentHooks
|
Callbacks to invoke during various points of the agent runtime. |
Source code in src/redpanda/agents/_agent.py
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
__init__
__init__(
name: str,
model: str,
instructions: str | None = None,
response_type: type[BaseModel] | None = None,
tools: list[Tool] | None = None,
mcp: list[MCPEndpoint] | None = None,
hooks: AgentHooks | None = None,
**kwargs: Any,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the agent. |
required |
model
|
str
|
The LLM model that the agent will use. Models follow the format of
" |
required |
instructions
|
str | None
|
The system prompt for the agent. |
None
|
response_type
|
type[BaseModel] | None
|
The Pydantic model that the response will be validated against. If None, the response will be a string. |
None
|
tools
|
list[Tool] | None
|
The tools exposed to the agent. |
None
|
mcp
|
list[MCPEndpoint] | None
|
The MCP endpoints that the agent can invoke. |
None
|
hooks
|
AgentHooks | None
|
Callbacks to invoke during various points of the agent runtime. |
None
|
**kwargs
|
Any
|
A dictionary of parameters that the model will use. These parameters are specific to the model. Examples: {"temperature": 0.5} {"max_tokens": 100} |
{}
|
Source code in src/redpanda/agents/_agent.py
run
async
Generate a response from the model given an input text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
The input text that the model will use to generate a response. |
required |
Returns: The generated response from the model.
Source code in src/redpanda/agents/_agent.py
AgentHooks
A class that receives callbacks on various lifecycle events for a specific agent.
Source code in src/redpanda/agents/_agent.py
MCPEndpoint
An Base class for all endpoints (ways to connect) to MCP servers.
Source code in src/redpanda/agents/_mcp.py
SSEMCPEndpoint
Bases: MCPEndpoint
A MCP endpoint that communicates with an MCP server over Server-Sent Events.
Source code in src/redpanda/agents/_mcp.py
__init__
Create a new SSEMCPEndpoint instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the SSE server. |
required |
cache_enabled
|
bool
|
Whether to cache the list of {tools,resources,prompts} from the server. |
True
|
Source code in src/redpanda/agents/_mcp.py
StdioMCPEndpoint
Bases: MCPEndpoint
A MCP endpoint that invokes a local process and communicates over stdin/stdout.
Source code in src/redpanda/agents/_mcp.py
__init__
Create a new StdioMCPEndpoint instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
StdioServerParameters
|
The parameters for the server. |
required |
cache_enabled
|
bool
|
Whether to cache the list of {tools,resources,prompts} from the server. |
True
|
Source code in src/redpanda/agents/_mcp.py
StreamableHTTPMCPEndpoint
Bases: MCPEndpoint
A MCP endpoint that communicates with an MCP server over HTTP streaming.
Source code in src/redpanda/agents/_mcp.py
__init__
Create a new StreamableHTTPMCPEndpoint instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the HTTP server. |
required |
cache_enabled
|
bool
|
Whether to cache the list of {tools,resources,prompts} from the server. |
True
|
Source code in src/redpanda/agents/_mcp.py
WebsocketMCPEndpoint
Bases: MCPEndpoint
A MCP endpoint that communicates with an MCP server over a WebSocket.
Source code in src/redpanda/agents/_mcp.py
__init__
Create a new WebsocketMCPEndpoint instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the WebSocket server. |
required |
cache_enabled
|
bool
|
Whether to cache the list of {tools,resources,prompts} from the server. |
True
|
Source code in src/redpanda/agents/_mcp.py
Tool
A tool is a function that can be called by an LLM with a set of parameters.
Source code in src/redpanda/agents/_tools.py
description
instance-attribute
An optional description of the tool.
parameters
instance-attribute
A dictionary of parameters (json_schema) that the tool requires.
__init__
__call__
async
Call the tool with the given arguments (should match the provided schema).
The return result can be:
- Pydantic model, which will be serialized to JSON and passed back to the model as text.
- string, which will be passed back to the model as text.
- ToolResponse, which allows for more structured content to be passed back to the model.
- Anything else will be serialized using json.dumps and passed back to the model as text.