Skip to main content

Target, Evaluate, Improve: A self-improving loop for agentic systems

Project description

TEI Loop

Target, Evaluate, Improve — a self-improving loop for agentic systems.

Get Started (2 steps)

pip install tei-loop
tei your_agent.py

That's it. TEI auto-detects your agent function, generates a test query, evaluates across 4 dimensions, and applies targeted improvements.

If pip is not found, use pip3. If tei is not found, use python3 -m tei_loop.cli.

What Happens When You Run tei your_agent.py

  1. TEI loads your file and finds the agent function (any callable that takes input and returns output)
  2. Auto-generates a relevant test query based on your agent's purpose
  3. Runs your agent and evaluates the output across 4 dimensions
  4. If any dimension can be improved, applies a targeted fix and re-runs
  5. Prints before/after scores

Options

python3 -m tei_loop agent.py                                    # Full loop, auto-detected
python3 -m tei_loop agent.py --function my_summarizer            # Specify which function
python3 -m tei_loop agent.py --query "custom input"              # Custom test query
python3 -m tei_loop agent.py --mode compare                      # Before/after comparison
python3 -m tei_loop agent.py --mode evaluate                     # Baseline only
python3 -m tei_loop agent.py --retries 5                         # More improvement cycles
python3 -m tei_loop agent.py --verbose                           # Detailed output

If your file has multiple functions, use --function to specify which one is your agent.

Python API

import asyncio
from tei_loop import TEILoop

def my_agent(query: str) -> str:
    # your agent logic
    return result

async def main():
    loop = TEILoop(agent=my_agent)
    result = await loop.run("your test query")
    print(result.summary())

asyncio.run(main())

4 Evaluation Dimensions

Dimension What it checks
Target Alignment Did the agent pursue the correct objective?
Reasoning Soundness Was the reasoning logical and non-contradictory?
Execution Accuracy Were the right tools called with correct parameters?
Output Integrity Is the output complete, accurate, and consistent?

Two Modes

Runtime mode (default): Per-query, 1-3 retries, fixes individual failures in seconds.

Development mode: Across many queries, proposes permanent prompt improvements.

dev_results = await loop.develop(
    queries=["query1", "query2", "query3", ...],
    max_iterations=50,
)

How It Works

TEI wraps any Python callable as a black box. No code changes to your agent needed.

When a dimension fails, TEI applies the right fix strategy:

Failure Fix Strategy
Target drift Re-anchor to original objective
Flawed reasoning Regenerate plan with failure context
Execution errors Correct tool calls and parameters
Output issues Repair factual errors and fill gaps

Configuration

TEI auto-detects your LLM provider from environment variables (OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY). No new accounts or API keys needed.

loop = TEILoop(
    agent=my_agent,
    eval_llm="gpt-5.2",       # Smartest for evaluation
    improve_llm="gpt-5-mini", # Cost-effective for fixes
)

Cost

Scenario Cost
Agent passes all dimensions ~$0.05
One improvement cycle ~$0.10
Full 3-retry loop ~$0.25

Works With Any Agent

TEI wraps any Python callable. No framework lock-in:

  • LangGraph agents
  • CrewAI crews
  • Custom Python functions
  • FastAPI endpoints
  • Any callable that takes input and returns output

License

MIT

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

tei_loop-0.1.5.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

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

tei_loop-0.1.5-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file tei_loop-0.1.5.tar.gz.

File metadata

  • Download URL: tei_loop-0.1.5.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tei_loop-0.1.5.tar.gz
Algorithm Hash digest
SHA256 aa86a43014a22f202cdb12f53b3d79150d089ee02339202043da76d2e2011d69
MD5 06f109ab1967bb2da4d77183c930dd0c
BLAKE2b-256 4c71fbcea428af2d25091b213b32d0515692e3ff942b2eee11701a5aa3ba0766

See more details on using hashes here.

File details

Details for the file tei_loop-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: tei_loop-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 48.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tei_loop-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 608a1e38f8b716816b98a48c219b0b084e6adf063e5cda6b2b04eb311516f6e8
MD5 7f7b11a774f4d816961a7dbe98437d5a
BLAKE2b-256 4a5afbdcd94045648bfab90e156638113cef82837f3ed73dd086ffe12aac0697

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