Overview
TheLLM class provides a simple, direct interface for interacting with language models without the full agent framework. It’s ideal for straightforward LLM calls where you don’t need tools, memory, or agent capabilities.
Constructor
Parameters
The LLM model to use. Supports any model from LiteLLM (e.g.,
"gpt-4o", "gemini/gemini-pro", "anthropic/claude-4").Optional system prompt to set the model’s behavior and context.
API key for the LLM provider. Falls back to
OPENAI_API_KEY or LLM_API_KEY environment variables if not provided.Methods
chat
Synchronous chat completion.input: User message as string or list of message dictionariestools: Optional list of tool definitions in OpenAI formattool_choice: Control tool usage -"auto","required", orNoneprevious_response_id: Optional ID to continue a previous conversation
achat
Asynchronous chat completion.- Same as
chat()method
Usage Examples
Basic Usage
With Custom API Key
Conversation History
Async Usage
With Tools
Environment Variables
The LLM class automatically uses API keys from environment variables:When to Use LLM vs Agentor
Use LLM when:
- You need simple, direct LLM calls
- You don’t need tool calling or agent capabilities
- You want minimal overhead and maximum control
- Building custom workflows or wrappers
Use Agentor when:
- You need tool calling and function execution
- You want agent-to-agent communication (A2A protocol)
- You need to serve agents as APIs
- You want built-in streaming and chat interfaces
- You need structured outputs or complex workflows
Error Handling
Related
- Agentor - Full agent framework with tools and APIs
- ModelSettings - Advanced model configuration
- Tools - Create function tools for agents
