API Reference

This section documents the main components of the agents-for-all framework.

class Agent(llm: Model, tools: List[Tool], max_retries: int = 10)

Bases: object

Agent class which can ‘do’ actions using llm and tools.

Example code:

from agents_for_all import Agent
from agents_for_all.llms.direct import DirectModel
from agents_for_all.tools.python import Python

llm = DirectModel(
    api_endpoint="http://127.0.0.1:1234/v1/chat/completions",
    model="deepseek-r1-distill-qwen-14b"
)
python = Python()

agent = Agent(llm=llm, tools=[python])
result = agent.do("Create a file with system date as the filename and txt as extension.")
print(result.output) # Final output
print(result.history) # History of steps taken
do(action: str) AgentResult

Do the given action using tools available and the llm specified.

Parameters:

action (str) – The action to perform.

Returns:

Final answer and execution trace.

Return type:

AgentResult

class AgentResult(output: str, history: List[str])

Bases: object

Represents the result of running an Agent’s .do() method.

output

The final summary response after executing all steps.

Type:

str

history

Step-by-step log of what happened during execution.

Type:

List[str]

history: List[str]
output: str
class Model

Bases: ABC

Abstract base class for models or model connectors to be exact. The models are initalized using its subclasses and can be used in agents. Some models are: - DirectModel (with api_endpoint, query_parameter_name, and other_parameters) - OpenAIModel - AntropicModel - GeminiModel

abstractmethod get_response(query: str) str

Get response from the LLM based on the given query.

Parameters:

query (str) – The query the LLM should respond to.

Returns:

The response to the query from the LLM.

Return type:

str

class DirectModel(api_endpoint: str, model: str, parameters: Dict | None = None)

Bases: Model

Direct model (or model connector to be exact) which connects to an LLM by using api_endpoint and parameters using OpenAI format (as done by LLMStudio).

Initialize the Direct model.

Parameters:
  • api_endpoint (str) – The api endpoint to call to get the response.

  • model (str) – The name of model.

  • parameters – (Dict, optional): Other parameters to be used while getting responses. Optional.

Returns:

None

get_response(query: str)

Get response from the LLM based on the given query.

Parameters:

query (str) – The query the LLM should respond to.

Returns:

The response to the query from the LLM.

Return type:

str

class OpenAIModel(model: str, api_key: str, parameters: Dict | None = None)

Bases: Model

OpenAI model connector using the official OpenAI SDK.

Initialize the OpenAI model.

Parameters:
  • model (str) – The model name (e.g., “gpt-4”, “gpt-3.5-turbo”).

  • api_key (str) – Your OpenAI API key.

  • parameters (Dict, optional) – Additional parameters (e.g., temperature).

get_response(query: str) str

Get response from OpenAI chat model.

Parameters:

query (str) – The query the model should respond to.

Returns:

The LLM’s text response.

Return type:

str

class AnthropicModel(model: str, api_key: str, parameters: Dict | None = None)

Bases: Model

Anthropic Claude model connector using the official SDK.

Initialize the Anthropic model.

Parameters:
  • model (str) – The model name (e.g., “claude-3-sonnet-20240229”).

  • api_key (str) – Your Anthropic API key.

  • parameters (Dict, optional) – Additional parameters (e.g., temperature).

get_response(query: str) str

Get response from Anthropic model.

Parameters:

query (str) – The query the model should respond to.

Returns:

The model’s response content.

Return type:

str

class GeminiModel(model: str, api_key: str, parameters: Dict | None = None)

Bases: Model

Google Gemini model connector using the official Google Generative AI SDK.

Initialize the Gemini model.

Parameters:
  • model (str) – Gemini model ID (e.g., “gemini-pro”).

  • api_key (str) – Your Google API key.

  • parameters (Dict, optional) – Additional generation parameters.

get_response(query: str) str

Get response from Gemini model.

Parameters:

query (str) – The prompt to send.

Returns:

The model’s response content.

Return type:

str

class Tool

Bases: ABC

Abstract base class for tools that can be used by agents.

Tools perform tasks or operations when invoked with structured input. Each subclass must implement the execute method and define a description for the LLM or agent to understand the capability of the tool.

abstract property description: str

A human-readable description of what the tool does. Should help the LLM choose the appropriate tool.

Returns:

Description of the tool’s purpose and capabilities.

Return type:

str

abstractmethod execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

abstract property name: str

The name of the tool. Should help the Agent run the appropriate tool.

Returns:

Name of the tool.

Return type:

str

class Python

Bases: Tool

A tool that can execute python codes.

Accepts code via input JSON and executes it on the host system using python..

property description: str

Explains that this tool executes raw Python code.

execute(input_json: Dict) str

Execute the given code string using python.

Parameters:

input_json (Dict) – Must contain a “code” key with the python command as value.

Returns:

The output or error string from the execution.

Return type:

str

property name: str

Python

class Shell

Bases: Tool

A tool that can execute shell commands.

Accepts input via input JSON and runs the command on the host shell.

property description: str

Executes shell commands on the host system. Input format:

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

Shell

class File

Bases: Tool

A tool that can perform basic file operations: read and write.

Accepts input via input JSON to read from or write to a file.

property description: str

Reads from or writes to files.

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

File

class Math

Bases: Tool

A tool to evaluate mathematical expressions safely using sympy.

Accepts an expression string and optional variables to substitute.

property description: str

Evaluates symbolic math expressions using sympy. Variables are substituted automatically.

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

Math

class WebFetcher

Bases: Tool

A tool that fetches the content of a web page.

Accepts a URL and returns the of its response body.

property description: str

Fetches a webpage using HTTP GET.

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

WebFetcher

class Email(smtp_host: str, smtp_port: int, username: str, password: str)

Bases: Tool

A tool that sends emails via SMTP.

Requires SMTP host, port, and login credentials during initialization.

Initialize the Email tool.

Parameters:
  • smtp_host (str) – SMTP server hostname (e.g., smtp.gmail.com).

  • smtp_port (int) – SMTP server port (e.g., 587).

  • username (str) – Email account username.

  • password (str) – Email account password or app-specific token.

Returns:

None

property description: str

Sends an email using SMTP.

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

Email

class DataAnalysis

Bases: Tool

A tool that runs arbitrary pandas code on a DataFrame created from CSV input.

Example

{

“csv”: “a,bn1,2n3,4”, “code”: “df[‘a’].mean()”

}

Note

Only use safe pandas expressions. This tool does not sandbox or restrict eval().

property description: str

Executes pandas code on a DataFrame loaded from CSV. The variable df is automatically defined as the parsed DataFrame.

execute(input_json: Dict) str

Execute the tool’s functionality based on input JSON.

Parameters:

input_json (Dict) – Input parameters to guide tool behavior.

Returns:

Output string describing the result of execution.

Return type:

str

property name: str

DataAnalysis