Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Tinygent is a tiny agentic framework - lightweight, easy to use (hopefully), and
```python
# uv sync --extra openai

from tinygent.tools.tool import tool
from tinygent.tools import tool
from tinygent.core.factory import build_agent

@tool
Expand Down
30 changes: 15 additions & 15 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ agent = TinyMAPAgent(
Create a simple tool.

```python
from tinygent.tools.tool import tool
from tinygent.tools import tool

@tool
def my_function(param: str) -> str:
Expand All @@ -234,7 +234,7 @@ def my_function(param: str) -> str:
Create and globally register a tool.

```python
from tinygent.tools.tool import register_tool
from tinygent.tools import register_tool

@register_tool(use_cache: bool = False, hidden: bool = False)
def my_function(param: str) -> str:
Expand All @@ -254,7 +254,7 @@ def my_function(param: str) -> str:
Create a tool requiring reasoning.

```python
from tinygent.tools.reasoning_tool import register_reasoning_tool
from tinygent.tools import register_reasoning_tool

@register_reasoning_tool(reasoning_prompt: str)
def my_function(param: str) -> str:
Expand All @@ -273,7 +273,7 @@ def my_function(param: str) -> str:
Create a just-in-time code generation tool.

```python
from tinygent.tools.jit_tool import jit_tool
from tinygent.tools import jit_tool

@jit_tool(jit_instruction: str)
def my_function(param: str):
Expand All @@ -292,7 +292,7 @@ def my_function(param: str):
### BufferChatMemory

```python
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

memory = BufferChatMemory()
```
Expand All @@ -308,7 +308,7 @@ memory = BufferChatMemory()
### SummaryBufferMemory

```python
from tinygent.memory.summary_buffer_memory import SummaryBufferMemory
from tinygent.memory import SummaryBufferMemory

memory = SummaryBufferMemory(
llm: BaseLLM,
Expand All @@ -321,7 +321,7 @@ memory = SummaryBufferMemory(
### WindowBufferMemory

```python
from tinygent.memory.window_buffer_memory import WindowBufferMemory
from tinygent.memory import WindowBufferMemory

memory = WindowBufferMemory(
window_size: int = 4,
Expand All @@ -333,7 +333,7 @@ memory = WindowBufferMemory(
### CombinedMemory

```python
from tinygent.memory.combined_memory import CombinedMemory
from tinygent.memory import CombinedMemory

memory = CombinedMemory(
memories: dict[str, BaseMemory],
Expand All @@ -347,7 +347,7 @@ memory = CombinedMemory(
### Base Middleware

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

class CustomMiddleware(TinyBaseMiddleware):
def on_start(self, *, run_id: str, task: str) -> None:
Expand Down Expand Up @@ -386,7 +386,7 @@ class CustomMiddleware(TinyBaseMiddleware):
### Register Middleware

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

@register_middleware('my_middleware')
class MyMiddleware(TinyBaseMiddleware):
Expand Down Expand Up @@ -424,7 +424,7 @@ Base class for Pydantic models.

```python
from pydantic import Field
from tinygent.core.types.base import TinyModel
from tinygent.core.types import TinyModel

class MyInput(TinyModel):
name: str = Field(..., description='User name')
Expand Down Expand Up @@ -523,7 +523,7 @@ logger.error("Error message")
### Color Printer

```python
from tinygent.utils.color_printer import TinyColorPrinter
from tinygent.utils import TinyColorPrinter

# Predefined colors
print(TinyColorPrinter.success("Success!"))
Expand All @@ -540,7 +540,7 @@ print(TinyColorPrinter.custom("Label", "Message", color="CYAN"))
### YAML Loader

```python
from tinygent.utils.yaml import tiny_yaml_load
from tinygent.utils import tiny_yaml_load

config = tiny_yaml_load('config.yaml')
```
Expand All @@ -553,11 +553,11 @@ config = tiny_yaml_load('config.yaml')

```python
from typing import List, Dict, Optional, Any
from tinygent.core.types.base import TinyModel
from tinygent.core.types import TinyModel
from tinygent.core.datamodels.tool import AbstractTool
from tinygent.core.datamodels.messages import TinyMessage
from tinygent.agents.base import BaseAgent
from tinygent.memory.base import BaseMemory
from tinygent.memory import BaseMemory
from tinygent.llms.base import BaseLLM
```

Expand Down
6 changes: 3 additions & 3 deletions docs/concepts/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ All agents support common configuration options:

```python
from tinygent.agents.react_agent import ReactAgentConfig
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

config = ReactAgentConfig(
llm='openai:gpt-4o-mini',
Expand Down Expand Up @@ -285,7 +285,7 @@ agent = build_agent(
Agents can remember conversation history using memory:

```python
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

agent = build_agent(
'react',
Expand All @@ -310,7 +310,7 @@ See [Memory](memory.md) for more details.
Customize agent behavior with middleware hooks:

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

class LoggingMiddleware(TinyBaseMiddleware):
def on_reasoning(self, *, run_id: str, reasoning: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/llms.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ LLMs can call functions (tools):

```python
from tinygent.core.factory import build_llm
from tinygent.tools.tool import tool
from tinygent.tools import tool

@tool
def get_weather(location: str) -> str:
Expand Down
20 changes: 10 additions & 10 deletions docs/concepts/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ agent.run("What is my name?")
With memory, agents remember context:

```python
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

agent = build_agent(
'react',
Expand Down Expand Up @@ -50,7 +50,7 @@ Tinygent provides 4 built-in memory types:
Stores all messages in a list:

```python
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

memory = BufferChatMemory()

Expand Down Expand Up @@ -97,7 +97,7 @@ print(memory.load_variables())
Summarizes old messages to save tokens:

```python
from tinygent.memory.summary_buffer_memory import SummaryBufferMemory
from tinygent.memory import SummaryBufferMemory

memory = SummaryBufferMemory(
llm=build_llm('openai:gpt-4o-mini'),
Expand Down Expand Up @@ -147,7 +147,7 @@ print(memory.load_variables())
Keeps only the last N messages:

```python
from tinygent.memory.window_buffer_memory import WindowBufferMemory
from tinygent.memory import WindowBufferMemory

memory = WindowBufferMemory(window_size=4) # Keep last 4 messages

Expand Down Expand Up @@ -191,9 +191,9 @@ agent.run("Message 5")
Combine different memory types:

```python
from tinygent.memory.combined_memory import CombinedMemory
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory.window_buffer_memory import WindowBufferMemory
from tinygent.memory import CombinedMemory
from tinygent.memory import BufferChatMemory
from tinygent.memory import WindowBufferMemory

# Full history + recent window
combined = CombinedMemory(
Expand Down Expand Up @@ -342,7 +342,7 @@ memory._chat_history.remove_filter('only_human')
Create custom memory classes:

```python
from tinygent.memory.base import BaseMemory
from tinygent.memory import BaseMemory

class KeywordMemory(BaseMemory):
"""Memory that only saves messages containing keywords."""
Expand Down Expand Up @@ -428,7 +428,7 @@ MultiStep agents benefit from memory:

```python
from tinygent.agents.multi_step_agent import TinyMultiStepAgent
from tinygent.memory.buffer_chat_memory import BufferChatMemory
from tinygent.memory import BufferChatMemory

agent = TinyMultiStepAgent(
llm=build_llm('openai:gpt-4o'),
Expand Down Expand Up @@ -502,7 +502,7 @@ memory = WindowBufferMemory(window_size=4)
Track memory changes with middleware:

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

class MemoryMonitorMiddleware(TinyBaseMiddleware):
def on_answer(self, *, run_id: str, answer: str) -> None:
Expand Down
16 changes: 6 additions & 10 deletions docs/concepts/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Think of middleware as **event listeners** for agent operations.
## Basic Example

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

class LoggingMiddleware(TinyBaseMiddleware):
def on_reasoning(self, *, run_id: str, reasoning: str, **kwargs) -> None:
Expand Down Expand Up @@ -131,7 +131,7 @@ Track the Thought-Action-Observation cycle:

```python
from typing import Any
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

class ReActCycleMiddleware(TinyBaseMiddleware):
def __init__(self) -> None:
Expand Down Expand Up @@ -361,7 +361,7 @@ agent = build_agent(
Make middleware reusable:

```python
from tinygent.agents.middleware.base import TinyBaseMiddleware
from tinygent.agents.middleware import TinyBaseMiddleware

@register_middleware('logging')
class LoggingMiddleware(TinyBaseMiddleware):
Expand Down Expand Up @@ -638,7 +638,7 @@ middleware = [
**Using Config Factory:**

```python
from tinygent.agents.middleware.tool_limiter import TinyToolCallLimiterMiddlewareConfig
from tinygent.agents.middleware import TinyToolCallLimiterMiddlewareConfig

# Create via config
config = TinyToolCallLimiterMiddlewareConfig(
Expand Down Expand Up @@ -726,9 +726,7 @@ selector = TinyLLMToolSelectorMiddleware(
**Custom Prompt Template:**

```python
from tinygent.core.prompts.agents.middleware.template.llm_tool_selector import (
LLMToolSelectorPromptTemplate
)
from tinygent.prompts.middleware import LLMToolSelectorPromptTemplate

custom_prompt = LLMToolSelectorPromptTemplate(
system="You are a tool selection expert. Select only the most relevant tools.",
Expand All @@ -745,9 +743,7 @@ selector = TinyLLMToolSelectorMiddleware(
**Using Config Factory:**

```python
from tinygent.agents.middleware.llm_tool_selector import (
TinyLLMToolSelectorMiddlewareConfig
)
from tinygent.agents.middleware import TinyLLMToolSelectorMiddlewareConfig

# Create via config
config = TinyLLMToolSelectorMiddlewareConfig(
Expand Down
12 changes: 6 additions & 6 deletions docs/concepts/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A tool is a **Python function** that:
**Example:**

```python
from tinygent.tools.tool import tool
from tinygent.tools import tool

@tool
def get_weather(location: str) -> str:
Expand Down Expand Up @@ -50,7 +50,7 @@ Tinygent provides 4 tool decorators for different use cases:
**Best for**: Quick local tools, no global registration needed

```python
from tinygent.tools.tool import tool
from tinygent.tools import tool

@tool
def calculator(expression: str) -> float:
Expand Down Expand Up @@ -81,7 +81,7 @@ agent = build_agent('react', llm='openai:gpt-4o-mini', tools=[calculator])
**Best for**: Reusable tools, CLI usage, multi-agent systems

```python
from tinygent.tools.tool import register_tool
from tinygent.tools import register_tool

@register_tool(use_cache=True)
def search_web(query: str) -> str:
Expand Down Expand Up @@ -136,7 +136,7 @@ expensive_api_call.clear_cache()
Reasoning tools require the agent to provide a rationale before calling:

```python
from tinygent.tools.reasoning_tool import register_reasoning_tool
from tinygent.tools import register_reasoning_tool

@register_reasoning_tool(
reasoning_prompt='Explain why you are performing this search.'
Expand Down Expand Up @@ -170,7 +170,7 @@ Observation: Found user record for John Doe
JIT tools generate and execute code at runtime based on agent instructions:

```python
from tinygent.tools.jit_tool import jit_tool
from tinygent.tools import jit_tool

@jit_tool(jit_instruction='Generate code to count from 1 to n, yielding each number.')
def count(n: int):
Expand Down Expand Up @@ -200,7 +200,7 @@ Tools can accept two input styles:

```python
from pydantic import Field
from tinygent.core.types.base import TinyModel
from tinygent.core.types import TinyModel

class WeatherInput(TinyModel):
location: str = Field(..., description='The city or location')
Expand Down
2 changes: 1 addition & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Explore practical examples of Tinygent in action.
### Simple Weather Agent

```python
from tinygent.tools.tool import tool
from tinygent.tools import tool
from tinygent.core.factory import build_agent

@tool
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Let's build a simple weather assistant.
Tools are functions that agents can call. Use the `@tool` decorator:

```python
from tinygent.tools.tool import tool
from tinygent.tools import tool

@tool
def get_weather(location: str) -> str:
Expand Down Expand Up @@ -184,7 +184,7 @@ asyncio.run(main())

```python
# weather_agent.py
from tinygent.tools.tool import tool
from tinygent.tools import tool
from tinygent.core.factory import build_agent

@tool
Expand Down
Loading