This project includes integration with Logfire for logging, tracing, and monitoring of the agent's operations.
The Logfire SDK is already included in the project dependencies. When you run poetry install, it will be installed automatically.
To authenticate with Logfire, run:
logfire authThis will open a browser window where you can authenticate. Upon successful authentication, credentials are stored in ~/.logfire/default.toml.
From the working directory where you will run your application, set the Logfire project:
logfire projects use kb-multi-agentAlternatively, you can set the LOGFIRE_PROJECT environment variable in your .env file.
In your .env file, set the following variables:
LOGFIRE_PROJECT=kb-multi-agent
LOGFIRE_TOKEN=<your-logfire-token> # Optional, if not using logfire auth
LOGGING_ENABLED=true
The Logfire integration provides the following features:
- Conversation Tracing: Each conversation is assigned a unique ID and trace ID for tracking
- Tool Usage Tracing: All tool calls are logged with inputs and outputs
- LLM Interaction Tracing: Model calls are logged with prompts and responses
- Error Tracking: Exceptions are logged with context information
- Response Times: Track how long different operations take
- Message Counts: Monitor the number of messages in conversations
- Tool Usage: See which tools are used most frequently
- Structured Logging: All logs include relevant context like conversation IDs
- Error Logging: Detailed error information for debugging
- Event Logging: Key events in the agent's lifecycle are logged
The Logfire integration is implemented in the following files:
mcp_agent/integrations/logfire_integration.py: The main integration modulemcp_agent/agent_factory.py: Factory that initializes and provides the loggermcp_agent/agent.py: Uses the logger for tracing agent operations
To view your logs and traces, go to the Logfire Dashboard and select your project.
If you encounter issues with Logfire integration:
- Check that you're authenticated with
logfire auth - Verify that the correct project is set with
logfire projects list - Ensure
LOGGING_ENABLED=truein your environment - Check for any error messages in the application logs
To disable Logfire logging, set LOGGING_ENABLED=false in your .env file or environment variables.