SwiftClaw

Deployment

Deployment OverviewProduction DeploymentCI/CD IntegrationRollback Strategies

Scaling

Scaling OverviewPerformance OptimizationCost OptimizationLoad Balancing

Security

Security OverviewAuthenticationSecrets ManagementSecurity Best Practices

Troubleshooting

TroubleshootingCommon IssuesDebuggingPerformance IssuesSupport
SwiftClaw

Debugging

Debug SwiftClaw agents effectively

Debugging

Learn how to effectively debug your SwiftClaw agents.

Debug Mode

Enable Debug Logging

# Enable debug mode
swiftclaw debug my-agent --enable

# Set log level
swiftclaw config my-agent --log-level debug

View Debug Logs

# Tail debug logs
swiftclaw logs my-agent --level debug --follow

# Filter by component
swiftclaw logs my-agent --level debug --component model

# Search debug logs
swiftclaw logs my-agent --level debug --search "tool_call"

Local Debugging

Run Agent Locally

# Run in development mode
swiftclaw dev my-agent

# Run with debug output
swiftclaw dev my-agent --debug

# Run with specific configuration
swiftclaw dev my-agent --config dev.json

Interactive Debugging

from swiftclaw import Agent

agent = Agent(name="my-agent", debug=True)

# Enable breakpoints
import pdb

@agent.on_message
async def handle_message(message):
    pdb.set_trace()  # Debugger breakpoint
    response = await agent.generate(message.content)
    return response

Request Tracing

Enable Tracing

# Enable request tracing
swiftclaw trace my-agent --enable

# View traces
swiftclaw trace my-agent --list

# View specific trace
swiftclaw trace my-agent --id trace-abc123

Trace Details

# View trace timeline
swiftclaw trace my-agent --id trace-abc123 --timeline

# Output:
# 0ms    Request received
# 5ms    Authentication verified
# 10ms   Memory search started
# 150ms  Memory search completed
# 160ms  Model inference started
# 2100ms Model inference completed
# 2105ms Tool call: search_database
# 2350ms Tool call completed
# 2355ms Response sent
# Total: 2355ms

Tool Debugging

Debug Tool Calls

@agent.tool(debug=True)
async def search_database(query: str):
    print(f"Tool called with query: {query}")
    
    result = await db.search(query)
    
    print(f"Tool returned {len(result)} results")
    
    return result

Tool Call Logs

# View tool call logs
swiftclaw logs my-agent --filter tool_calls

# View failed tool calls
swiftclaw logs my-agent --filter tool_calls.failed

Memory Debugging

Inspect Memory

# View memory contents
swiftclaw memory inspect my-agent

# Search memory
swiftclaw memory search my-agent --query "user preferences"

# Export memory
swiftclaw memory export my-agent --output memory.json

Memory Metrics

# View memory metrics
swiftclaw metrics my-agent --metric memory

# Memory usage by type
swiftclaw metrics my-agent --metric memory --breakdown

Model Debugging

View Model Requests

# View model requests
swiftclaw logs my-agent --filter model.requests

# View model responses
swiftclaw logs my-agent --filter model.responses

# View model errors
swiftclaw logs my-agent --filter model.errors

Token Usage

# View token usage
swiftclaw metrics my-agent --metric tokens

# Token usage by request
swiftclaw analyze my-agent --tokens --period 24h

Performance Profiling

Profile Agent

# Run profiler
swiftclaw profile my-agent --duration 5m

# Output:
# Component         Time    Percentage
# Model Inference   2100ms  70%
# Memory Search     150ms   5%
# Tool Calls        250ms   8%
# Other             500ms   17%

Identify Bottlenecks

# Analyze slow requests
swiftclaw analyze my-agent --slow-requests --threshold 2s

# Generate flame graph
swiftclaw profile my-agent --flamegraph --output profile.svg

Error Debugging

View Error Stack Traces

# View recent errors
swiftclaw errors my-agent --limit 10

# View error details
swiftclaw errors my-agent --error-id abc123

# View error stack trace
swiftclaw errors my-agent --error-id abc123 --stack-trace

Error Patterns

# Analyze error patterns
swiftclaw analyze my-agent --errors --period 7d

# Group errors by type
swiftclaw errors my-agent --group-by type

Network Debugging

View Network Requests

# View outgoing requests
swiftclaw logs my-agent --filter network.outgoing

# View failed requests
swiftclaw logs my-agent --filter network.failed

# View request latency
swiftclaw metrics my-agent --metric network-latency

Test Connectivity

# Test external API connectivity
swiftclaw test connectivity my-agent --api openai

# Test database connectivity
swiftclaw test connectivity my-agent --database

Debugging Tools

Interactive Shell

# Open interactive shell
swiftclaw shell my-agent

# Execute commands
> agent.status()
> agent.memory.search("test")
> agent.generate("Hello")

Remote Debugging

# Enable remote debugging
swiftclaw debug my-agent --remote --port 5678

# Connect with debugger
python -m debugpy --connect localhost:5678

Common Debugging Scenarios

Debugging Slow Responses

# Enable performance tracing
swiftclaw trace my-agent --enable

# Make request
curl https://api.swiftclaw.io/agents/my-agent/invoke \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"message": "test"}'

# View trace
swiftclaw trace my-agent --latest --timeline

Debugging Memory Issues

# Add memory debugging
@agent.on_message
async def handle_message(message):
    # Log memory before
    print(f"Memory before: {agent.memory.size()}")
    
    response = await agent.generate(message.content)
    
    # Log memory after
    print(f"Memory after: {agent.memory.size()}")
    
    return response

Debugging Tool Failures

@agent.tool
async def problematic_tool(param: str):
    try:
        result = await external_api.call(param)
        return result
    except Exception as e:
        # Log detailed error
        agent.log.error(f"Tool failed: {e}", exc_info=True)
        raise

Debug Configuration

Development Config

{
  "debug": true,
  "logging": {
    "level": "debug",
    "format": "detailed",
    "includeStackTrace": true
  },
  "tracing": {
    "enabled": true,
    "sampleRate": 1.0
  },
  "profiling": {
    "enabled": true
  }
}

Production Config

{
  "debug": false,
  "logging": {
    "level": "info",
    "format": "json",
    "includeStackTrace": false
  },
  "tracing": {
    "enabled": true,
    "sampleRate": 0.1
  },
  "profiling": {
    "enabled": false
  }
}

Performance Impact: Debug mode increases resource usage. Disable in production.

Best Practices

1. Use Structured Logging

agent.log.info("Processing request", extra={
    "user_id": user_id,
    "request_id": request_id,
    "message_length": len(message)
})

2. Add Context to Errors

try:
    result = await risky_operation()
except Exception as e:
    agent.log.error(
        "Operation failed",
        exc_info=True,
        extra={"operation": "risky_operation", "params": params}
    )
    raise

3. Use Correlation IDs

@agent.on_message
async def handle_message(message):
    correlation_id = generate_correlation_id()
    
    agent.log.info("Request started", extra={"correlation_id": correlation_id})
    
    try:
        response = await agent.generate(message.content)
        agent.log.info("Request completed", extra={"correlation_id": correlation_id})
        return response
    except Exception as e:
        agent.log.error("Request failed", extra={"correlation_id": correlation_id})
        raise

Next Steps

  • Common Issues
  • Performance Issues
  • Support

How is this guide ?

Last updated on

Common Issues

Solutions to common problems

Performance Issues

Diagnose and resolve agent performance problems

On this page

Debugging
Debug Mode
Enable Debug Logging
View Debug Logs
Local Debugging
Run Agent Locally
Interactive Debugging
Request Tracing
Enable Tracing
Trace Details
Tool Debugging
Debug Tool Calls
Tool Call Logs
Memory Debugging
Inspect Memory
Memory Metrics
Model Debugging
View Model Requests
Token Usage
Performance Profiling
Profile Agent
Identify Bottlenecks
Error Debugging
View Error Stack Traces
Error Patterns
Network Debugging
View Network Requests
Test Connectivity
Debugging Tools
Interactive Shell
Remote Debugging
Common Debugging Scenarios
Debugging Slow Responses
Debugging Memory Issues
Debugging Tool Failures
Debug Configuration
Development Config
Production Config
Best Practices
1. Use Structured Logging
2. Add Context to Errors
3. Use Correlation IDs
Next Steps