ollama_agent_base
A lightweight tool-calling agent framework for Ollama.
This project provides a simple way to create AI agents that can call Python functions ("tools"), execute actions, and maintain conversation history.
Features
- Simple tool registration
- Automatic tool argument inspection
- Multi-step agent execution loop
- JSON-based tool calling
- Conversation memory
- Custom system prompts
- Configurable Ollama model and host
Installation
pip install ollama_base_agent
Quick Start
Create a Tool
from ollama_agent_base import Tool
def print_tool(message: str):
print(message)
return {
"printed": message
}
print_to_terminal_tool = Tool(
name="print",
func=print_tool,
description="Send a message to the user via terminal output"
)
Register Tools
from ollama_agent_base import register_tools
import tools
register_tools([
tools.print_to_terminal_tool
])
Create an Agent
from ollama_agent_base import Agent
agent = Agent(
system_prompt=None,
model="gemma3"
)
agent.reset()
Ask a Question
agent.ask(
"What programming language is easiest to print in?"
)
Tool Definition
Tools are regular Python functions wrapped in a Tool object.
def add(a: int, b: int):
return {
"result": a + b
}
add_tool = Tool(
name="add",
func=add,
description="Add two numbers together"
)
Arguments are automatically detected from the function signature.
Example:
def greet(name: str, times: int = 1):
...
Produces:
{
"name": "str",
"times": "int (default=1)"
}
Tool Registration
Single tool:
register_tools(
my_tool
)
Multiple tools:
register_tools(
tool_a,
tool_b,
tool_c
)
Or:
register_tools(*tool_list)
Agent Configuration
agent = Agent(
model="gemma3",
host="http://127.0.0.1:11434",
max_steps=10
)
Parameters
| Parameter | Description |
|---|---|
| model | Ollama model name |
| host | Ollama server URL |
| max_steps | Maximum tool iterations |
Environment Variables
Supported environment variables:
OLLAMA_MODEL=gemma3
OLLAMA_HOST=http://127.0.0.1:11434
Example Project Structure
project/
│
├── main.py
├── tools.py
│
└── src/
└── ollama_agent_base/
├── __init__.py
└── agent.py
Example
from ollama_agent_base import Agent, register_tools
import tools
register_tools(
tools.print_to_terminal_tool
)
agent = Agent(
system_prompt=None
)
agent.reset()
agent.ask(
"Say hello"
)
How It Works
- User sends a message.
- Agent sends conversation history and tool definitions to Ollama.
- Model responds with a JSON tool call.
- Tool executes.
- Result is added to conversation history.
- Process repeats until completion.
Goals
This project aims to be:
- Lightweight
- Easy to understand
- Minimal dependencies
- Easy to extend
- Compatible with local Ollama models
It is intentionally much smaller than frameworks such as LangChain while still supporting tool-calling workflows.
Metadata
Release files for ollama-agent-base 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ollama_agent_base-0.1.1.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ollama_agent_base-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / ollama_agent_base-0.1.1.tar.gz
| Download URL | ollama_agent_base-0.1.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cfee21e19f47519be49da1cfd66eba649981113f955194966b0e07b671a73277
|
|
BLAKE2b-256 checksum How to use checksums |
5f2d7d91e90ba3743bc8e6dabec46c629480905a115a194aeec8b8ceebc528d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ollama_agent_base-0.1.1-py3-none-any.whl
| Download URL | ollama_agent_base-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f143021b6d86ea7849adab740c538ab797ef045cc34e0a1ed22077d576ef1217
|
|
BLAKE2b-256 checksum How to use checksums |
4e2f1ee17a67a818bf9b7a3d384685398b3960721526ff71aa41a5458740fa89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|