Simple ollama ai agent base for allowing a ai to run python functions
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ollama_agent_base-0.1.1.tar.gz.
File metadata
- Download URL: ollama_agent_base-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfee21e19f47519be49da1cfd66eba649981113f955194966b0e07b671a73277
|
|
| MD5 |
08ddf3d06f31d6d0fabf1489a842392e
|
|
| BLAKE2b-256 |
5f2d7d91e90ba3743bc8e6dabec46c629480905a115a194aeec8b8ceebc528d9
|
File details
Details for the file ollama_agent_base-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ollama_agent_base-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f143021b6d86ea7849adab740c538ab797ef045cc34e0a1ed22077d576ef1217
|
|
| MD5 |
3b4015daa3889c36886f804c02088221
|
|
| BLAKE2b-256 |
4e2f1ee17a67a818bf9b7a3d384685398b3960721526ff71aa41a5458740fa89
|