Skip to main content

Overview

The LLM 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

model
str
required
The LLM model to use. Supports any model from LiteLLM (e.g., "gpt-4o", "gemini/gemini-pro", "anthropic/claude-4").
system_prompt
str
default:"None"
Optional system prompt to set the model’s behavior and context.
api_key
str
default:"None"
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.
Parameters:
  • input: User message as string or list of message dictionaries
  • tools: Optional list of tool definitions in OpenAI format
  • tool_choice: Control tool usage - "auto", "required", or None
  • previous_response_id: Optional ID to continue a previous conversation
Returns: LiteLLM response object Example:

achat

Asynchronous chat completion.
Parameters:
  • Same as chat() method
Returns: LiteLLM response object Example:

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

  • Agentor - Full agent framework with tools and APIs
  • ModelSettings - Advanced model configuration
  • Tools - Create function tools for agents
Last modified on May 5, 2026