KodeAgent is a minimalistic, frameworkless approach to building debuggable AI agents. KodeAgent is a small (~2,000 lines of pure Python) engine designed to be the robust reasoning core inside your larger system, not the entire platform.
KodeAgent adheres to the Unix Philosophy: do one thing well and integrate seamlessly.
Use KodeAgent because it offers:
- Stateless and Scalable: Designed to be stateless with zero overhead, making it perfect for serverless and high-throughput microservices where you manage the state.
- ReAct & CodeAct: KodeAgent supports both ReAct and CodeAct agent paradigms out-of-the-box, enabling agents to reason and act using tools or by generating and executing code.
- LLM Agnostic: Built on LiteLLM, KodeAgent easily swaps between models, such as Gemini and OpenAI, without requiring any changes to the core agent logic.
- Lightweight Foundation: At only ~2,000 lines of pure Python and just a few dependencies, KodeAgent provides the agent primitives without any of the architectural bloat found in some frameworks.
- The Glass Box: The architecture is frameworkless and minimal, allowing you to read the entire Pure Python source and debug without fighting opaque abstraction layers.
Also, here are a few reasons why you shouldn't use KodeAgent:
- KodeAgent is actively evolving, meaning some aspects may change.
- You want to use some of the well-known frameworks.
- You need a full-fledged platform with built-in state management, memory, and other components.
Install KodeAgent via pip:
pip install kodeagentOr if you want to clone the KodeAgent GitHub repository locally and run from there, use:
git clone https://github.com/barun-saha/kodeagent.git
python -m venv venv
source venv/bin/activate
# venv\Scripts\activate.bat # Windows
pip install -r requirements.txtNow, in your application code, create a ReAct agent and run a task like this (see examples/kodeagent_quick_start.py):
from kodeagent import ReActAgent, print_response
from kodeagent.tools import read_webpage, search_web
agent = ReActAgent(
name='Web agent',
model_name='gemini/gemini-2.5-flash-lite',
tools=[search_web, read_webpage],
max_iterations=5,
)
for task in [
'What are the festivals in Paris? How they differ from Kolkata?',
]:
print(f'User: {task}')
async for response in agent.run(task):
print_response(response, only_final=True)You can also create a CodeActAgent, which leverages the core CodeAct pattern to generate and execute Python code on the fly for complex tasks. For example:
from kodeagent import CodeActAgent
from kodeagent.tools import read_webpage, search_web, extract_as_markdown
agent = CodeActAgent(
name='Web agent',
model_name='gemini/gemini-2.0-flash-lite',
tools=[search_web, read_webpage, extract_as_markdown],
run_env='host',
max_iterations=7,
allowed_imports=[
're', 'requests', 'ddgs', 'urllib', 'requests', 'bs4',
'pathlib', 'urllib.parse', 'markitdown'
],
pip_packages='ddgs~=9.5.2;beautifulsoup4~=4.14.2;"markitdown[all]";',
)That's it! Your agent should start solving the task and keep streaming the updates. For more examples, including how to provide files as inputs, see the kodeagent.py module.
KodeAgent uses LiteLLM, enabling it to work with any capable LLM. Currently, KodeAgent has been tested with Gemini 2.5 Flash Lite. For advanced tasks, you can try Gemini 2.5 Pro.
LLM model names, parameters, and keys should be set as per LiteLLM API Keys documentation. For example, set the GEMINI_API_KEY environment variable (add in the .env file you are running from source code) to use Gemini API. Additionally, you can set OPENAI_API_KEY for OpenAI models; set ANTHROPIC_API_KEY for Claude models; and so on. For Azure OpenAI models, set AZURE_API_KEY, AZURE_API_BASE, and AZURE_API_VERSION environment variables.
CodeActAgent executes LLM-generated code to leverage the tools. KodeAgent currently supports two different code run environments:
host: The Python code will be run on the system where you created this agent. In other words, where the application is running.e2b: The Python code will be run on an E2B sandbox. You will need to set theE2B_API_KEYenvironment variable.
With host as the code running environment, no special steps are required, since it uses the current Python installation. However, with e2b, code (and tools) are copied to a different environment and are executed there. Therefore, some additional setup may be required.
For example, the Python modules that are allowed to be used in code should be explicitly specified using allowed_imports. In addition, any additional Python package that may need to be installed should be specified as a comma-separated list via pip_packages.
KodeAgent is under active development. Capabilities are limited. Use with caution.
KodeAgent comes with the following built-in tools:
calculator: A simple calculator tool to perform basic arithmetic operations.download_file: A tool to download a file from a given URL.extract_as_markdown: A tool to read file contents and return as Markdown using MarkItDown.read_webpage: A tool to read a webpage using BeautifulSoup.search_arxiv: A tool to search arXiv for research papers and return summaries and links.search_web: A web search tool using DuckDuckGo to fetch top search results.search_wikipedia: A tool to search Wikipedia and return summaries and links.transcribe_audio: A tool to transcribe audio files using OpenAI's Whisper via Fireworks API. Need to set theFIREWORKS_API_KEYenvironment variable.transcribe_youtube: A tool to fetch YouTube video transcripts.
Check out the docstrings of these tools in the tools.py module for more details.
To add a new tool, use the @tool decorator from kodeagent.tools module. For example:
from kodeagent import tool
@tool
def my_tool(param1: str) -> str:
"""Description of the tool.
Args:
param1 (str): Description of param1.
Returns:
str: Description of the return value.
"""
# Tool implementation here
return 'result'Module imports and all variables should be inside the tool function. If you're using CodeActAgent, KodeAgent will execute the tool function in isolation.
For further details, refer to the API documentation.
KodeAgent logs the LLM calls and usage using Langfuse. The LiteLLM calls set the trace ID to the task ID. The model name as well as the response format and retry attempts for the generations are also logged (see the screenshot below). To enable tracing, create your Langfuse account and set the LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST environment variables. Read more about Langfuse integration with LiteLLM.
sequenceDiagram
autonumber
actor User
participant Agent
participant Planner
participant LLM as LLM/Prompts
participant Tools
User->>Agent: run(task)
Agent->>Planner: create_plan(task)
Planner->>LLM: request AgentPlan JSON (agent_plan.txt)
LLM-->>Planner: AgentPlan JSON
Planner-->>Agent: planner.plan set
loop For each step
Agent->>Planner: get_formatted_plan()
Agent->>LLM: codeact prompt + {plan, history}
LLM-->>Agent: Thought + Code
Agent->>Tools: execute tool call(s)
Tools-->>Agent: Observation
Agent->>Planner: update_plan(thought, observation, task_id)
end
Agent-->>User: Final Answer / Failure (per codeact spec)
To run unit tests, use:
python -m pytest .\tests\unit -v --cov --cov-report=htmlFor integration tests involving calls to APIs, use:
python -m pytest .\tests\integration -v --cov --cov-report=htmlGemini and E2B API keys should be set in the .env file for integration tests to work.
A Kaggle notebook for benchmarking KodeAgent is also available.
To be updated.
KodeAgent heavily borrows code and ideas from different places, such as:
- LlamaIndex
- Smolagents
- LangGraph
- Building ReAct Agents from Scratch: A Hands-On Guide using Gemini
- LangGraph Tutorial: Build Your Own AI Coding Agent
- Aider, Antigravity, CodeRabbit, GitHub Copilot, Jules, ...
AI agents can occasionally cause unintended or unpredictable side effects. We urge users to use KodeAgent with caution. Always review generated code and test agents rigorously in a constrained, non-production environment before deployment.
LIMITATION OF LIABILITY: By using this software, you agree that KodeAgent, its developers, contributors, supporters, and any other associated entities shall not be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software.
