Skip to main content

TAgent - Modular AI Agent Framework with Dynamic Tool Discovery

Project description

๐Ÿค– TAgent - Modular AI Agent Framework

Python 3.8+ License: MIT Code Style: Black

Build powerful AI agents with modular tools and automatic discovery

TAgent is a production-ready framework for creating AI agents with modular, reusable tools. It features automatic tool discovery, dynamic schema loading, and a powerful CLI for rapid development and deployment.

Built on LiteLLM - Universal LLM API for seamless integration with 100+ language models including OpenAI, Anthropic, Azure, Google, and local models.

โœจ Key Features

  • ๐Ÿ” Automatic Tool Discovery - Finds and loads tagent.tools.py files automatically
  • ๐Ÿ—๏ธ Modular Architecture - Reusable tools across different projects
  • ๐Ÿ“‹ Dynamic Schema Loading - Pydantic schemas from tagent.output.py files
  • ๐Ÿš€ Production CLI - Professional command-line interface with console scripts
  • ๐Ÿ”„ Intelligent Agent Loop - State machine-controlled adaptive planning, execution, and evaluation
  • ๐ŸŽฏ State Machine Control - Prevents infinite loops and enforces logical action sequences
  • ๐Ÿ› ๏ธ Rich Tool Ecosystem - Travel planning, e-commerce, and custom tools
  • ๐ŸŽฏ Type-Safe Output - Structured results with Pydantic validation
  • ๐Ÿ“ Comprehensive Logging - Beautiful retro-style terminal output

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/Tavernari/tagent.git
cd tagent

# One-command setup (creates venv, installs everything)
make clean-install

# Activate virtual environment
source .venv/bin/activate

Basic Usage

# Test the CLI with built-in travel tools
tagent "Plan a trip from London to Rome for 2025-09-10 to 2025-09-17 with budget $2000" \
  --search-dir examples/travel_planning_cli \
  --max-iterations 10

# Quick discovery test
make cli-discovery-test

# See all available commands
make help

๐Ÿ“ Creating Your Own Tools

1. Create Tool Functions (myproject/tagent.tools.py)

from typing import Dict, Any, Tuple, Optional

def web_search_tool(state: Dict[str, Any], args: Dict[str, Any]) -> Optional[Tuple[str, Any]]:
    """Search the web for information."""
    query = args.get('query', '')
    
    # Your implementation here
    results = perform_web_search(query)
    
    return ('search_results', results)

def data_analysis_tool(state: Dict[str, Any], args: Dict[str, Any]) -> Optional[Tuple[str, Any]]:
    """Analyze data and generate insights."""
    data = args.get('data', [])
    
    # Your analysis logic
    insights = analyze_data(data)
    
    return ('analysis_insights', insights)

2. Define Output Schema (myproject/tagent.output.py)

from pydantic import BaseModel, Field
from typing import List

class ResearchReport(BaseModel):
    title: str = Field(..., description="Report title")
    summary: str = Field(..., description="Executive summary") 
    findings: List[str] = Field(default=[], description="Key findings")
    recommendations: List[str] = Field(default=[], description="Actionable recommendations")
    confidence_score: float = Field(..., description="Confidence in results (0-1)")

# Required variable name
output_schema = ResearchReport

3. Run Your Agent

tagent "Research the latest trends in AI and create a comprehensive report" \
  --search-dir myproject \
  --model openrouter/ollama/gemma3 \
  --verbose

๐ŸŽฏ Examples

Travel Planning Agent

# Complete travel itinerary with flights, hotels, activities
tagent "Plan a 7-day trip to Tokyo with cultural activities and budget $3000" \
  --search-dir examples/travel_planning_cli

E-commerce Analysis

# Business intelligence and product recommendations
tagent "Analyze customer data and suggest product improvements" \
  --search-dir examples/ecommerce \
  --model openrouter/ollama/gemma3

Custom Research

# Multi-source research with structured output
tagent "Research sustainable energy trends and create executive summary" \
  --tools ./research/tagent.tools.py \
  --output ./research/tagent.output.py

๐Ÿ› ๏ธ CLI Commands

Development Commands

make help                  # Show all commands
make install              # Install in virtual environment  
make clean-install        # Clean install (recommended)
make test                 # Run test suite
make lint                 # Code quality checks
make format               # Format code with black

CLI Commands

make cli-help             # Show CLI help
make cli-discovery-test   # Test tool discovery
make cli-test             # Full travel example
make cli-demo             # Generate demo GIF

# Direct CLI usage (after source .venv/bin/activate)
tagent --help
tagent "your goal" --search-dir path/to/tools

๐Ÿ—๏ธ Architecture

TAgent Framework
โ”œโ”€โ”€ ๐Ÿ” Tool Discovery Engine
โ”‚   โ”œโ”€โ”€ Automatic file scanning  
โ”‚   โ”œโ”€โ”€ Function signature validation
โ”‚   โ””โ”€โ”€ Dynamic imports
โ”œโ”€โ”€ ๐Ÿค– Intelligent Agent Core
โ”‚   โ”œโ”€โ”€ LLM-powered decision making (via LiteLLM)
โ”‚   โ”œโ”€โ”€ Adaptive planning
โ”‚   โ”œโ”€โ”€ Tool execution
โ”‚   โ””โ”€โ”€ Goal evaluation
โ”œโ”€โ”€ ๐Ÿ“‹ Schema Management
โ”‚   โ”œโ”€โ”€ Pydantic integration
โ”‚   โ”œโ”€โ”€ Type-safe outputs
โ”‚   โ””โ”€โ”€ Validation
โ””โ”€โ”€ ๐Ÿš€ Production CLI
    โ”œโ”€โ”€ Console scripts
    โ”œโ”€โ”€ Rich terminal UI
    โ””โ”€โ”€ Error handling

๐Ÿ”ง Core Dependencies

  • LiteLLM - Universal LLM integration supporting 100+ models
  • Pydantic - Type-safe data validation and schemas
  • Rich - Beautiful terminal UI and progress indicators

๐Ÿ“Š Built-in Tools

Travel Planning (examples/travel_planning_cli/)

  • โœˆ๏ธ Flight search with budget filtering
  • ๐Ÿจ Hotel recommendations with preferences
  • ๐ŸŽฏ Activity suggestions by interest
  • ๐Ÿ’ฐ Cost calculation and budgeting
  • ๐Ÿ“ Itinerary generation

E-commerce (examples/ecommerce/)

  • ๐Ÿ“ˆ Sales analysis and trends
  • ๐Ÿ‘ฅ Customer behavior insights
  • ๐Ÿ›๏ธ Product recommendations
  • ๐Ÿ’ก Business intelligence

๐Ÿ”ง Advanced Usage

Custom Models

TAgent provides a sophisticated model configuration system, allowing you to specify different Large Language Models (LLMs) for various stages of the agent's operation. This offers fine-grained control and optimization, as different tasks (planning, execution, summarization, evaluation, finalization) might benefit from different models (e.g., a faster, cheaper model for simple execution steps, and a more capable one for complex planning).

Key Concepts:

  • Agent Steps: TAgent's internal lifecycle is broken down into distinct steps: PLANNER, EXECUTOR, SUMMARIZER, EVALUATOR, and FINALIZER.
  • Step-Specific Models: You can assign a particular LLM to each of these steps.
  • Global Fallback Model: A default model that will be used for any step that doesn't have a specific model assigned.
  • Configuration Priority: The system follows a clear hierarchy to determine which model to use for a given step, from highest to lowest precedence:
    1. AgentModelConfig Object (Programmatic): If you pass an AgentModelConfig object to the agent, its step-specific models take the highest precedence, followed by its global model.
    2. Environment Variables: Step-specific environment variables (e.g., TAGENT_PLANNER_MODEL) override the global environment variable (TAGENT_MODEL).
    3. CLI --model Argument: The --model argument in the CLI sets the global fallback model.
    4. Default Model: If no other configuration is found, a hardcoded default model (gpt-3.5-turbo) is used.

How to Configure Models:

You have several ways to configure the models, from most specific (programmatic) to least specific (default):

  1. Using AgentModelConfig (Programmatic - for advanced use cases): For programmatic control, you can create an AgentModelConfig instance and pass it to the agent's run method. This allows you to define specific models for each step and a global fallback.

    from src.tagent.model_config import AgentModelConfig
    
    config = AgentModelConfig(
        tagent_model="gpt-4o",  # Global fallback for all steps
        tagent_planner_model="gpt-4o-mini", # Specific model for planning
        tagent_evaluator_model="gpt-4o-mini", # Specific model for evaluation
        api_key="sk-your-api-key" # Optional API key for the LLM service
    )
    # Then pass this config object to your agent's run method, e.g.:
    # agent.run(goal="...", config=config)
    
  2. Using Environment Variables (Recommended for persistent setup): You can set environment variables to control the models. This is ideal for setting up your preferred models across different runs without modifying code or CLI commands every time.

    • Global Model:

      export TAGENT_MODEL="openrouter/google/gemma-7b-it"
      

      This model will be used for all agent steps unless a step-specific environment variable is set.

    • Step-Specific Models:

      export TAGENT_PLANNER_MODEL="openrouter/openai/gpt-4o-mini"
      export TAGENT_EXECUTOR_MODEL="openrouter/anthropic/claude-3-haiku"
      export TAGENT_SUMMARIZER_MODEL="openrouter/google/gemma-7b-it"
      export TAGENT_EVALUATOR_MODEL="openrouter/openai/gpt-4o-mini"
      export TAGENT_FINALIZER_MODEL="openrouter/google/gemma-7b-it"
      

      These will override TAGENT_MODEL for their respective steps.

  3. Using the CLI --model Argument (Quick and easy): The existing --model argument in the CLI now sets the global fallback model. This is the simplest way to quickly change the model for a single run.

    tagent "your goal" --model openrouter/google/gemma-7b-it
    

    If you also have environment variables set, the environment variables will take precedence over the --model argument.

This new system provides maximum flexibility, allowing users to tailor the LLM usage to their specific needs, optimizing for cost, speed, or capability at each stage of the agent's operation.

For a complete list of supported models and integrations, please visit the LiteLLM Provider Documentation.

Multiple Tool Directories

# Search multiple directories
tagent "complex task" \
  --search-dir ./core-tools \
  --search-dir ./specialized-tools \
  --search-dir ./custom-tools \
  --recursive

API Configuration

# Set API key
export OPENAI_API_KEY="your-key"
# or
tagent "goal" --api-key your-key-here

๐ŸŽฌ Demo

Generate an animated demo:

make cli-demo  # Creates examples/tagent_cli_demo.gif

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Follow code style: make format && make lint
  4. Add tests: pytest tests/
  5. Commit changes: git commit -m "Add amazing feature"
  6. Push branch: git push origin feature/amazing-feature
  7. Open Pull Request

Development Setup

git clone https://github.com/Tavernari/tagent.git
cd tagent
make clean-install
source .venv/bin/activate
make test

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐ŸŒŸ Why TAgent?

  • ๐Ÿ”ฅ Rapid Development: Create agents in minutes, not hours
  • ๐Ÿ”ง Modular Design: Reuse tools across projects
  • ๐Ÿš€ Production Ready: Professional CLI and error handling
  • ๐ŸŽฏ Type Safety: Pydantic schemas ensure data integrity
  • ๐Ÿค– Intelligent: LLM-powered adaptive behavior
  • ๐Ÿ“ˆ Scalable: From prototypes to production systems

๐ŸŽ‰ Star History

If TAgent helps you build amazing AI agents, please give it a โญ!


Built with โค๏ธ for the AI community

๐Ÿ› Report Bug | โœจ Request Feature

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

tagent-0.4.0.tar.gz (62.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tagent-0.4.0-py3-none-any.whl (50.7 kB view details)

Uploaded Python 3

File details

Details for the file tagent-0.4.0.tar.gz.

File metadata

  • Download URL: tagent-0.4.0.tar.gz
  • Upload date:
  • Size: 62.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for tagent-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6f2693dd6e8df34e236c96ff7909c5c826dda7aa19334b10fe4216f0ec5fdfad
MD5 f51ec1ae4b2cc2f225a66aacf6637c6d
BLAKE2b-256 3c9ca1d0d4406cd9bcd6137d7e024ac15f7b2c23910a8e96917b75e9cfc593e9

See more details on using hashes here.

File details

Details for the file tagent-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: tagent-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 50.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for tagent-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65cc0364ea9992d2f04d94a7a1383fc706f47ca699fb923a0ce9d73a6b015ede
MD5 5cb469bf3455b3fd08a1aab3e0bc6d15
BLAKE2b-256 b915e1ed2a7218330106379dd71d3bc7d472234c61b3f074b2ba14a9cf193f8f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page