Agent API¶
The core agent implementation for PatchPal, providing the main interface for interacting with LLMs and executing tools.
Creating an Agent¶
patchpal.agent.create_agent(model_id='anthropic/claude-sonnet-4-5', custom_tools=None, litellm_kwargs=None)
¶
Create and return a PatchPal agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
LiteLLM model identifier (default: anthropic/claude-sonnet-4-5) |
'anthropic/claude-sonnet-4-5'
|
custom_tools
|
Optional[List[Callable]]
|
Optional list of Python functions to use as custom tools. Each function should have type hints and a docstring. |
None
|
litellm_kwargs
|
Optional[Dict[str, Any]]
|
Optional dict of extra parameters to pass to litellm.completion() (e.g., {"reasoning_effort": "high"} for reasoning models) |
None
|
Returns:
| Type | Description |
|---|---|
PatchPalAgent
|
A configured PatchPalAgent instance |
Example
def calculator(x: int, y: int) -> str: '''Add two numbers.
Args:
x: First number
y: Second number
'''
return str(x + y)
agent = create_agent(custom_tools=[calculator]) response = agent.run("What's 5 + 3?")
With reasoning model¶
agent = create_agent( model_id="ollama_chat/gpt-oss:20b", litellm_kwargs={"reasoning_effort": "high"} )
Source code in patchpal/agent.py
Agent Class¶
patchpal.agent.PatchPalAgent(model_id='anthropic/claude-sonnet-4-5', custom_tools=None, litellm_kwargs=None)
¶
Simple agent that uses LiteLLM for tool calling.
Initialize the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
LiteLLM model identifier |
'anthropic/claude-sonnet-4-5'
|
custom_tools
|
Optional[List[Callable]]
|
Optional list of Python functions to add as tools |
None
|
litellm_kwargs
|
Optional[Dict[str, Any]]
|
Optional dict of extra parameters to pass to litellm.completion() (e.g., {"reasoning_effort": "high"} for reasoning models) |
None
|
Source code in patchpal/agent.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
run(user_message, max_iterations=100)
¶
Run the agent on a user message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_message
|
str
|
The user's request |
required |
max_iterations
|
int
|
Maximum number of agent iterations (default: 100) |
100
|
Returns:
| Type | Description |
|---|---|
str
|
The agent's final response |
Source code in patchpal/agent.py
Helper Functions¶
patchpal.agent._is_bedrock_arn(model_id)
¶
Usage Example¶
from patchpal.agent import create_agent
# Create agent with default model
agent = create_agent()
# Or specify a model
agent = create_agent(model_id="anthropic/claude-sonnet-4-5")
# Run a task
response = agent.run("List all Python files")
print(response)
# Check token usage
print(f"Total tokens: {agent.cumulative_input_tokens + agent.cumulative_output_tokens:,}")
Related¶
- Python API Guide - Comprehensive guide to using the Python API
- Context Management - How context windows are managed
- Custom Tools - Adding your own tools to the agent