Spaces:
Sleeping
Sleeping
Agent Framework
A flexible framework for building AI agents with tool support, MCP integration, and multi-step reasoning.
Structure
agent_framework/
βββ __init__.py # Package exports
βββ models.py # Core data models (Message, ToolCall, Event, ExecutionContext)
βββ tools.py # BaseTool and FunctionTool classes
βββ llm.py # LlmClient and request/response models
βββ agent.py # Agent and AgentResult classes
βββ mcp.py # MCP tool loading utilities
βββ utils.py # Helper functions for tool definitions
Quick Start
from agent_framework import Agent, LlmClient, FunctionTool
# Define a tool
def calculator(expression: str) -> float:
"""Calculate mathematical expressions."""
return eval(expression)
# Create the agent
agent = Agent(
model=LlmClient(model="gpt-5-mini"),
tools=[FunctionTool(calculator)],
instructions="You are a helpful assistant.",
)
# Run the agent
result = await agent.run("What is 1234 * 5678?")
print(result.output) # "7006652"
Components
Models (models.py)
Message: Text messages in conversationsToolCall: LLM's request to execute a toolToolResult: Result from tool executionEvent: Recorded occurrence during agent executionExecutionContext: Central storage for execution state
Tools (tools.py)
BaseTool: Abstract base class for all toolsFunctionTool: Wraps Python functions as tools
LLM (llm.py)
LlmClient: Client for LLM API calls using LiteLLMLlmRequest: Request object for LLM callsLlmResponse: Response object from LLM calls
Agent (agent.py)
Agent: Main agent class that orchestrates reasoning and tool executionAgentResult: Result of an agent execution
MCP (mcp.py)
load_mcp_tools(): Load tools from MCP servers
Utils (utils.py)
function_to_input_schema(): Convert function signature to JSON Schemaformat_tool_definition(): Format tool definition in OpenAI formattool: Decorator to convert functions to tools
Usage Examples
Basic Tool Usage
from agent_framework import FunctionTool
def my_function(x: int, y: int) -> int:
"""Add two numbers."""
return x + y
tool = FunctionTool(my_function)
result = await tool.execute(context, x=5, y=3) # 8
Using the @tool Decorator
from agent_framework import tool
@tool
def multiply(a: float, b: float) -> float:
"""Multiply two numbers."""
return a * b
# multiply is now a FunctionTool instance
MCP Tool Integration
from agent_framework import load_mcp_tools
import os
connection = {
"command": "npx",
"args": ["-y", "tavily-mcp@latest"],
"env": {"TAVILY_API_KEY": os.getenv("TAVILY_API_KEY")}
}
mcp_tools = await load_mcp_tools(connection)
agent = Agent(
model=LlmClient(model="gpt-5-mini"),
tools=mcp_tools,
)
Installation
The framework uses:
pydanticfor data validationlitellmfor LLM API callsmcpfor MCP server integration
Install dependencies:
pip install pydantic litellm mcp