|
| 1 | +--- |
| 2 | +description: Agentuity Python SDK API Reference |
| 3 | +globs: "agents/**/*.py" |
| 4 | +--- |
| 5 | + |
| 6 | +# Agentuity Python SDK |
| 7 | + |
| 8 | +The Agentuity Python SDK provides a powerful framework for building AI agents in Python. This cursor rules file helps you navigate the SDK's core interfaces and methods. |
| 9 | + |
| 10 | +## Core Interfaces |
| 11 | + |
| 12 | +### Agent Handler |
| 13 | + |
| 14 | +The main handler function for an agent: |
| 15 | + |
| 16 | +```python |
| 17 | +async def run( |
| 18 | + request: AgentRequest, |
| 19 | + response: AgentResponse, |
| 20 | + context: AgentContext |
| 21 | +) -> Any: |
| 22 | + # Agent implementation |
| 23 | + pass |
| 24 | +``` |
| 25 | + |
| 26 | +### AgentRequest |
| 27 | + |
| 28 | +The `AgentRequest` class provides methods for accessing request data: |
| 29 | + |
| 30 | +- `request.trigger`: Gets the trigger type of the request |
| 31 | +- `request.metadata`: Gets metadata associated with the request |
| 32 | +- `request.get(key, default)`: Gets a value from the metadata |
| 33 | +- `request.data.contentType`: Gets the content type of the request payload |
| 34 | +- `request.data.json`: Gets the payload as a JSON object |
| 35 | +- `request.data.text`: Gets the payload as a string |
| 36 | +- `request.data.binary`: Gets the payload as bytes |
| 37 | + |
| 38 | +### AgentResponse |
| 39 | + |
| 40 | +The `AgentResponse` class provides methods for creating responses: |
| 41 | + |
| 42 | +- `response.json(data, metadata)`: Creates a JSON response |
| 43 | +- `response.text(data, metadata)`: Creates a text response |
| 44 | +- `response.binary(data, content_type, metadata)`: Creates a binary response |
| 45 | +- `response.html(data, metadata)`: Creates an HTML response |
| 46 | +- `response.empty(metadata)`: Creates an empty response |
| 47 | +- `response.handoff(params, args, metadata)`: Redirects to another agent |
| 48 | +- Media-specific methods: `pdf()`, `png()`, `jpeg()`, `gif()`, `mp3()`, `mp4()`, etc. |
| 49 | + |
| 50 | +### AgentContext |
| 51 | + |
| 52 | +The `AgentContext` class provides access to various capabilities: |
| 53 | + |
| 54 | +- `context.logger`: Logging functionality |
| 55 | +- `context.kv`: Key-Value storage |
| 56 | +- `context.vector`: Vector storage |
| 57 | +- `context.get_agent(agent_id_or_name)`: Gets a handle to a remote agent |
| 58 | +- `context.tracer`: OpenTelemetry tracing |
| 59 | +- Environment properties: `sdkVersion`, `devmode`, `orgId`, `projectId`, etc. |
| 60 | + |
| 61 | +## Storage APIs |
| 62 | + |
| 63 | +### Key-Value Storage |
| 64 | + |
| 65 | +Access through `context.kv`: |
| 66 | + |
| 67 | +- `await context.kv.get(name, key)`: Retrieves a value |
| 68 | +- `await context.kv.set(name, key, value, params)`: Stores a value with optional params |
| 69 | +- `await context.kv.delete(name, key)`: Deletes a value |
| 70 | + |
| 71 | +### Vector Storage |
| 72 | + |
| 73 | +Access through `context.vector`: |
| 74 | + |
| 75 | +- `await context.vector.upsert(name, *documents)`: Inserts or updates vectors |
| 76 | +- `await context.vector.search(name, params)`: Searches for vectors |
| 77 | +- `await context.vector.delete(name, *ids)`: Deletes vectors |
| 78 | + |
| 79 | +## Logging |
| 80 | + |
| 81 | +Access through `context.logger`: |
| 82 | + |
| 83 | +- `context.logger.debug(message, *args, **kwargs)`: Logs a debug message |
| 84 | +- `context.logger.info(message, *args, **kwargs)`: Logs an informational message |
| 85 | +- `context.logger.warn(message, *args, **kwargs)`: Logs a warning message |
| 86 | +- `context.logger.error(message, *args, **kwargs)`: Logs an error message |
| 87 | +- `context.logger.child(**kwargs)`: Creates a child logger with additional context |
| 88 | + |
| 89 | +## Best Practices |
| 90 | + |
| 91 | +- Use type hints for better IDE support |
| 92 | +- Import types from `agentuity` |
| 93 | +- Use structured error handling with try/except blocks |
| 94 | +- Leverage the provided logger for consistent logging |
| 95 | +- Use the storage APIs for persisting data |
| 96 | +- Consider agent communication for complex workflows |
| 97 | + |
| 98 | +For complete documentation, visit: https://agentuity.dev/SDKs/python/api-reference |
0 commit comments