Skip to main content

Transform LLM Agents into High-Performance Engines with DAG optimization

Project description

Tygent Python - Speed & Efficiency Layer for AI Agents

CI PyPI version Python 3.8+ License: CC BY-NC 4.0

Transform your existing AI agents into high-performance engines with intelligent parallel execution and optimized scheduling. Tygent aims to speed up workflows and reduce costs with no code changes required.

Quick Start

Installation

pip install tygent

Basic Usage - Accelerate Any Function

from tygent import accelerate


# Your existing code
def research_topic(topic):
    # Your existing research logic
    return {"summary": f"Research on {topic}"}

# Wrap the function to run via Tygent's scheduler
accelerated_research = accelerate(research_topic)
result = accelerated_research("AI trends")

Zero-Lift Framework Patching

import asyncio

import tygent

# Apply patches for any installed integrations
tygent.install()

from google.generativeai import GenerativeModel

model = GenerativeModel("gemini-pro")
result = asyncio.run(model.generate_content("Hello"))

Multi-Agent System

import asyncio

from tygent import MultiAgentManager

# Create manager
manager = MultiAgentManager("customer_support")

# Add agents to the system
class AnalyzerAgent:
    def analyze(self, question):
        return {"intent": "password_reset", "keywords": ["reset", "password"]}

class ResearchAgent:
    def search(self, keywords):
        return {"help_docs": ["Reset guide", "Account recovery"]}

manager.add_agent("analyzer", AnalyzerAgent())
manager.add_agent("researcher", ResearchAgent())

# Execute with optimized communication
result = asyncio.run(
    manager.execute({"question": "How do I reset my password?"})
)

Key Features

  • ๐Ÿš€ Speed Improvement: Intelligent parallel execution of independent operations
  • ๐Ÿ’ฐ Cost Reduction: Optimized token usage and API call batching
  • ๐Ÿ”ง Zero Code Changes: Drop-in acceleration for existing functions and agents
  • ๐Ÿง  Smart DAG Optimization: Automatic dependency analysis and parallel scheduling
  • ๐Ÿ”„ Dynamic Adaptation: Runtime DAG modification based on conditions and failures
  • ๐ŸŽฏ Multi-Framework Support: Works with CrewAI, HuggingFace, Google AI, and custom agents
  • ๐Ÿ“„ Plan Parsing: Build DAGs directly from framework plans or dictionaries
  • ๐Ÿ“‹ Auditing & Tracing: Inspect plans, hook into node execution, and record results

Architecture

Tygent uses Directed Acyclic Graphs (DAGs) to model and optimize your agent workflows:

Your Sequential Code:        Tygent Optimized:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Step 1        โ”‚         โ”‚   Step 1        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                           โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Step 2        โ”‚   โ†’     โ”‚ Step 2  โ”‚Step 3 โ”‚ (Parallel)
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                           โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Step 3        โ”‚         โ”‚   Step 4        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Advanced Usage

Dynamic DAG Modification

from tygent import accelerate
from tygent.adaptive_executor import AdaptiveExecutor


# Workflow that adapts to failures and conditions
@accelerate
async def travel_planning_workflow(destination):
    # Tygent automatically handles:
    # - API failures with fallback services
    # - Conditional branching based on weather
    # - Resource-aware execution adaptation
    
    weather = await get_weather(destination)  # Primary API
    # Auto-fallback to backup_weather_service if primary fails
    
    if weather["condition"] == "rain":
        # Dynamically adds indoor alternatives node
        recommendations = await get_indoor_alternatives(destination)
    else:
        recommendations = await get_outdoor_activities(destination)
    
    return recommendations

Integration Examples

Example: Accelerating a LangChain Agent

from tygent import accelerate


# Your existing LangChain agent
class MockLangChainAgent:
    def run(self, query):
        return f"LangChain response to: {query}"

agent = MockLangChainAgent()

# Accelerate it
accelerated_agent = accelerate(agent)
result = accelerated_agent.run("Analyze market trends")

Example: LangGraph Multi-Agent Workflow

See examples/langgraph_tata_capital_example.py for a complete example that builds a LangGraph workflow from a JSON agent specification, uses OpenAI's ChatGPT model, and compares execution with and without Tygent to measure latency and token savings. It also provides curated benchmark conversations of varying lengths (5 to 50 messages) that map to each agent state so you can reproduce multi-step flows without crafting transcripts manually.

Custom Multi-Agent System

import asyncio

from tygent import DAG, LLMNode, MultiAgentManager, ToolNode

# Create a DAG for manual workflow control
dag = DAG("content_generation")

def research_function(inputs):
    return {"research_data": f"Data about {inputs.get('topic', 'general')}"}

class SimpleLLMNode(LLMNode):
    async def execute(self, inputs):
        # Normally this would call an LLM; here we just format text
        return {"outline": f"Outline for {inputs.get('research_data', '')}"}

dag.add_node(ToolNode("research", research_function))
dag.add_node(SimpleLLMNode("outline"))
dag.add_edge("research", "outline")

result = asyncio.run(dag.execute({"topic": "AI trends"}))

Parsing Plans

Tygent can convert structured plans into executable DAGs with parse_plan.

from tygent import Scheduler, accelerate, parse_plan

plan = {
    "name": "math",
    "steps": [
        {"name": "add", "func": add_fn, "critical": True},
        {"name": "mult", "func": mult_fn, "dependencies": ["add"]},
    ],
}

# Build a DAG manually
dag, critical = parse_plan(plan)
scheduler = Scheduler(dag)
scheduler.priority_nodes = critical

# Or accelerate the plan directly (works with frameworks exposing `get_plan`)
run_plan = accelerate(plan)

If you have multiple plans (e.g. produced by different LLMs) you can combine them into a single DAG:

from tygent import parse_plans, Scheduler

dag, critical = parse_plans([plan_a, plan_b])
scheduler = Scheduler(dag)
scheduler.priority_nodes = critical

Testing

Running Tests

Make sure to install the package in editable mode before executing the tests.

# Install test dependencies
pip install pytest pytest-asyncio

# Install package in development mode
pip install -e .

# Run core tests (always pass)
pytest tests/test_dag.py tests/test_multi_agent.py -v

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=tygent --cov-report=html

Test Coverage

Our test suite covers:

  • Core DAG functionality: Node management, topological sorting, parallel execution
  • Multi-agent communication: Message passing, agent orchestration, conversation history
  • Async operations: Proper async/await handling, concurrent execution
  • Error handling: Graceful failure recovery, fallback mechanisms

Current Status: 14/14 core tests passing โœ…

Recent Test Fixes (v1.1)

  • Fixed Message interface to match TypedDict implementation
  • Corrected async timestamp handling using asyncio.get_event_loop().time()
  • Added pytest.ini configuration for proper async test support
  • Updated MultiAgentManager constructor calls with required name parameter
  • Removed dependencies on non-existent classes (AgentRole, OptimizationSettings)

CI/CD

GitHub Actions workflow automatically runs:

  • Multi-version testing: Python 3.8, 3.9, 3.10, 3.11
  • Multi-platform: Ubuntu, macOS, Windows
  • Code quality: flake8 linting, black formatting, mypy type checking
  • Package building: Automated wheel and source distribution creation
  • PyPI publishing: Automatic publishing on main branch pushes
  • Coverage reporting: HTML and LCOV coverage reports

Triggers: Every push and pull request to main/develop branches

Framework Integrations

Supported Frameworks

  • CrewAI: Multi-agent coordination
  • Microsoft Semantic Kernel: Plugin optimization
  • LangSmith: Experiment tracking integration
  • LangFlow: Visual workflow authoring
  • Custom Agents: Universal function acceleration

External Service Integrations

  • OpenAI: GPT-4, GPT-3.5-turbo optimization
  • Google AI: Gemini model integration
  • Microsoft Azure: Azure OpenAI service
  • Salesforce: Einstein AI and CRM operations
  • HuggingFace: Transformer models

Performance Benchmarks

Benchmark tests live under tests/benchmarks/ and compare sequential execution with Tygent's scheduler. Typical results on a small DAG of four dependent tasks:

Scenario Time (s)
Sequential execution ~0.70
Scheduler (1 worker) ~0.72
Scheduler (2 workers) ~0.52

Run the benchmarks using:

pip install -e .
pytest tests/benchmarks/ -v

Development

Project Structure

tygent-py/
โ”œโ”€โ”€ tygent/
โ”‚   โ”œโ”€โ”€ __init__.py          # Main exports
โ”‚   โ”œโ”€โ”€ accelerate.py        # Core acceleration wrapper
โ”‚   โ”œโ”€โ”€ dag.py              # DAG implementation
โ”‚   โ”œโ”€โ”€ nodes.py            # Node types (Tool, LLM, etc.)
โ”‚   โ”œโ”€โ”€ scheduler.py        # Execution scheduler
โ”‚   โ”œโ”€โ”€ multi_agent.py      # Multi-agent system
โ”‚   โ”œโ”€โ”€ adaptive_executor.py # Dynamic DAG modification
โ”‚   โ””โ”€โ”€ integrations/       # Framework integrations
โ”œโ”€โ”€ tests/                  # Test suite
โ”œโ”€โ”€ examples/              # Usage examples
โ””โ”€โ”€ docs/                  # Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Install development dependencies: pip install -e ".[dev]"
  4. Run tests: pytest tests/ -v
  5. Commit changes: git commit -am 'Add feature'
  6. Push to branch: git push origin feature-name
  7. Submit a pull request

Code Quality

  • Type hints: Full type annotation coverage
  • Testing: Comprehensive test suite with >90% coverage
  • Linting: Black formatting, flake8 compliance
  • Documentation: Detailed docstrings and examples

VS Code Extension

The vscode-extension folder provides a simple Visual Studio Code extension. Use the Tygent: Enable Agent command to insert tygent.install() into the active Python file, converting existing agent implementations to use Tygent automatically.

Cursor Extension

The cursor-extension folder ships a Cursor editor extension with the Tygent: Enable Agent (Cursor) command. It adds tygent.install() (and the import if missing) to the current Python file while respecting shebang headers, giving Cursor users the same one-click conversion workflow.

Editor Extension Guide

Need a step-by-step walkthrough for packaging and using the extensions in your environment? Read the customer extension README for installation, usage, and benchmarking instructions.

License

Creative Commons Attribution-NonCommercial 4.0 International License.

See LICENSE for details.

Support


Transform your agents. Accelerate your AI.

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

tygent-0.5.0.tar.gz (67.5 kB view details)

Uploaded Source

Built Distribution

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

tygent-0.5.0-py3-none-any.whl (81.3 kB view details)

Uploaded Python 3

File details

Details for the file tygent-0.5.0.tar.gz.

File metadata

  • Download URL: tygent-0.5.0.tar.gz
  • Upload date:
  • Size: 67.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tygent-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7ce37026c3b27167b5bc623ca9f2b05fb1a15ca9099b8f4c429ac591ca282dcd
MD5 4825191a6b6a692d4471b0f4c1517844
BLAKE2b-256 0de47c65e94a1e46a61c5533fd5c5ae0cfb198eb3c73f80bd093283250ef4117

See more details on using hashes here.

Provenance

The following attestation bundles were made for tygent-0.5.0.tar.gz:

Publisher: python-publish.yml on tygentai/tygent-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tygent-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: tygent-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 81.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tygent-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 994e9309b7ce5d3845bd75df940fcb4a74bee10982824ced3aac9c65f0459fdd
MD5 f27280e5bd2502d8b172f0523887d07f
BLAKE2b-256 afbff049c4a7ab3165f2a480892abce4d002e25c01bbf62627886890ae14b92b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tygent-0.5.0-py3-none-any.whl:

Publisher: python-publish.yml on tygentai/tygent-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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