Python SDK Guide

Python SDK Guide

Learn how to integrate AgentWall with your Python agent frameworks.

Installation

Basic Usage

Simple Chat Completion

Run-Level Tracking

Track multi-step agent tasks with run IDs:

Streaming Responses

Handle streaming responses for real-time output:

LangChain Integration

Use AgentWall with LangChain:

CrewAI Integration

Use AgentWall with CrewAI agents:

Error Handling

Handle AgentWall-specific errors:

Budget Tracking

Monitor costs and budgets:

Best Practices

  1. Always use run IDs for multi-step tasks - Enables loop detection and cost tracking
  2. Handle 429 responses - Loop detection blocks requests with 429 status
  3. Set appropriate timeouts - LLM responses can take time
  4. Monitor costs - Track spending to stay within budget
  5. Use streaming for long responses - Better UX and real-time feedback
  6. Implement retry logic - Handle transient failures gracefully

Troubleshooting

Loop Detection Blocking Requests

If you see 429 Loop detected errors:

  • Check if you're sending the same prompt repeatedly
  • Use different run IDs for different tasks
  • Verify your agent logic isn't stuck in a loop

Authentication Errors

If you see 401 Unauthorized:

  • Verify your API key is correct
  • Check the key hasn't been revoked
  • Ensure the key is passed in the Authorization header

Timeout Issues

If requests timeout:

  • Increase the timeout value
  • Check your network connection
  • Verify the API is responding (check /health endpoint)

Next Steps