Lightweight Python framework for building LLM agents with tool calling and RAG
Project description
llm-agent-base
A lightweight Python library for building LLM agents with tool calling and retrieval-augmented generation (RAG). Works with any OpenAI-compatible API (OpenRouter, OpenAI, Ollama, etc.).
Installation
pip install llm-agent-base
Features
- Tool calling — register plain Python functions as LLM-callable tools; schemas are built automatically from type hints and docstrings
- RAG — ingest a folder of documents (
.txt,.md,.json,.pdf) into a FAISS vector index and inject relevant chunks into every prompt - Pipelines — chain multiple agents so each agent's output becomes the next agent's input
- Debug mode — optional logging of tool calls and knowledge retrievals
Quick start
from llm_agent_base import AgentBase, LLMConnectionConfig
config = LLMConnectionConfig(model="openai/gpt-4o-mini", api_key="...")
agent = AgentBase(
system_prompt="You are a helpful assistant.",
llm_config=config,
)
print(agent.run("What is the capital of France?"))
The default base_url points to OpenRouter, which gives access to many models through a single API key. You can swap it for the OpenAI base URL or any other compatible endpoint.
Usage
Tool calling
Register any Python function as a tool. The function name becomes the tool name, the docstring becomes its description, and the type hints define the parameter schema.
from llm_agent_base import AgentBase, LLMConnectionConfig
config = LLMConnectionConfig(model="openai/gpt-4o-mini", api_key="...")
def get_weather(city: str) -> str:
"""Return the current weather for a given city."""
return f"The weather in {city} is sunny and 22°C."
def add(a: int, b: int) -> int:
"""Add two integers and return the result."""
return a + b
agent = AgentBase(
system_prompt="You are a helpful assistant. Use the available tools when needed.",
llm_config=config,
)
agent.register_tool(get_weather)
agent.register_tool(add)
print(agent.run("What is the weather in Tokyo and what is 10 + 20?"))
register_tool can also be used as a decorator:
@agent.register_tool
def search_orders(order_id: str) -> str:
"""Look up an order by ID."""
...
RAG (knowledge base)
Place your documents in a folder (organised into subdirectories by topic). Call ingest_knowledge once to embed and index them, then run as normal — relevant chunks are automatically injected into the system prompt.
knowledge/
├── products/
│ ├── faq.md
│ └── pricing.json
└── support/
└── sla.md
from llm_agent_base import AgentBase, LLMConnectionConfig
config = LLMConnectionConfig(model="openai/gpt-4o-mini", api_key="...")
agent = AgentBase(
system_prompt="You are a product assistant. Answer using only the provided context.",
llm_config=config,
knowledge_folder_path="knowledge",
knowledge_index_dir=".kb_index", # where the FAISS index is saved
knowledge_top_k=3, # number of chunks injected per prompt
)
# Build and persist the index (run once, or when documents change)
agent.ingest_knowledge(save=True)
# On subsequent runs, load from disk instead of re-embedding
# agent.load_knowledge()
print(agent.run("Who founded the company and when?"))
Agent pipelines
Chain agents so the output of one becomes the input of the next:
from llm_agent_base import AgentBase, AgentPipelineBase, LLMConnectionConfig
config = LLMConnectionConfig(model="openai/gpt-4o-mini", api_key="...")
researcher = AgentBase(
system_prompt="Extract the key facts from the user's question.",
llm_config=config,
)
writer = AgentBase(
system_prompt="Turn the provided facts into a concise, friendly summary.",
llm_config=config,
)
pipeline = AgentPipelineBase(agents=[researcher, writer])
print(pipeline.run("Tell me about the Acme Corp product lineup."))
Debug mode
Pass debug=True to any agent to print tool invocations and knowledge retrievals to stdout:
agent = AgentBase(..., debug=True)
[debug] Retrieving knowledge
[debug] tool 'get_weather' args={'city': 'Tokyo'} result=The weather in Tokyo is sunny and 22°C.
API reference
| Class / function | Description |
|---|---|
LLMConnectionConfig |
Dataclass holding model name, base URL, API key, and embedding model |
AgentBase |
Single agent with optional tool calling and RAG |
AgentPipelineBase |
Chains multiple AgentBase instances in sequence |
KnowledgeBase |
Document ingestion, embedding, and FAISS retrieval |
DocumentChunk |
Dataclass representing a retrieved text chunk |
build_tool_schema |
Builds an OpenAI-compatible tool schema from a function |
execute_tool_loop |
Runs the agentic tool-calling loop against any OpenAI-compatible client |
Project details
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 llm_agent_base-0.1.1.tar.gz.
File metadata
- Download URL: llm_agent_base-0.1.1.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ee01b8267829d4175cdc55d86c2c377df1d2692801ab46a564c8d11d6d7e871
|
|
| MD5 |
ff45a15f8f526c9754b238cd41a8c97e
|
|
| BLAKE2b-256 |
e4021104e2ba4f2c0d39cec6e735b15f75bd09e9e777c129baa6df238f67749d
|
Provenance
The following attestation bundles were made for llm_agent_base-0.1.1.tar.gz:
Publisher:
publish.yml on mksochota16/llm-agent-base
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_agent_base-0.1.1.tar.gz -
Subject digest:
0ee01b8267829d4175cdc55d86c2c377df1d2692801ab46a564c8d11d6d7e871 - Sigstore transparency entry: 2187905059
- Sigstore integration time:
-
Permalink:
mksochota16/llm-agent-base@87d2fa567bbc65467acfd583ce9c605d566598ff -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mksochota16
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@87d2fa567bbc65467acfd583ce9c605d566598ff -
Trigger Event:
push
-
Statement type:
File details
Details for the file llm_agent_base-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_agent_base-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bf63de2e440e91953649d1fd02c3056e1f8080327829869209a4a2ee1a2dbdf
|
|
| MD5 |
1eb16bc70052003734e67c4c62d9cb3b
|
|
| BLAKE2b-256 |
e56b7108a158fe42d25bf55fa248ab911db889e584b69667d96216be2b35787f
|
Provenance
The following attestation bundles were made for llm_agent_base-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on mksochota16/llm-agent-base
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_agent_base-0.1.1-py3-none-any.whl -
Subject digest:
1bf63de2e440e91953649d1fd02c3056e1f8080327829869209a4a2ee1a2dbdf - Sigstore transparency entry: 2187905065
- Sigstore integration time:
-
Permalink:
mksochota16/llm-agent-base@87d2fa567bbc65467acfd583ce9c605d566598ff -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mksochota16
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@87d2fa567bbc65467acfd583ce9c605d566598ff -
Trigger Event:
push
-
Statement type: