Metadata-Version: 2.4
Name: textagents
Version: 0.0.1
Summary: Declarative, file-based PydanticAI agents
Keywords: llm,pydantic,agents,evaluation,judge,pydantic-ai
Author: Jan Siml
Author-email: Jan Siml <49557684+svilupp@users.noreply.github.com>
License-Expression: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Dist: pydantic>=2.0
Requires-Dist: pydantic-ai>=0.1.0
Requires-Dist: python-dotenv>=1.2.1
Requires-Dist: textprompts>=0.1.0
Requires-Dist: typer>=0.9.0
Requires-Dist: pytest>=8.0 ; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23 ; extra == 'dev'
Requires-Dist: pytest-cov>=4.0 ; extra == 'dev'
Requires-Dist: ty ; extra == 'dev'
Requires-Dist: ruff>=0.1.0 ; extra == 'dev'
Requires-Dist: mkdocs>=1.6 ; extra == 'docs'
Requires-Dist: mkdocs-material>=9.5 ; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.27 ; extra == 'docs'
Requires-Dist: logfire>=0.1.0 ; extra == 'logfire'
Requires-Python: >=3.11
Provides-Extra: dev
Provides-Extra: docs
Provides-Extra: logfire
Description-Content-Type: text/markdown

# textagents

[![PyPI version](https://img.shields.io/pypi/v/textagents.svg)](https://pypi.org/project/textagents/)
[![Python versions](https://img.shields.io/pypi/pyversions/textagents.svg)](https://pypi.org/project/textagents/)
[![CI status](https://github.com/svilupp/textagents/workflows/CI/badge.svg)](https://github.com/svilupp/textagents/actions)
[![License](https://img.shields.io/pypi/l/textagents.svg)](https://github.com/svilupp/textagents/blob/main/LICENSE)
[![Docs](https://img.shields.io/badge/docs-textagents-blue?style=flat&logo=python&logoColor=white)](https://siml.earth/textagents/)

> **Let agents write better agents.**

> [!WARNING]
> **Alpha Release**: This package is in early development. Expect bugs, breaking changes, and incomplete features. Use at your own risk and please [report issues](https://github.com/svilupp/textagents/issues).

## What is textagents?

**textagents** is an opinionated wrapper around [PydanticAI](https://ai.pydantic.dev/) and [textprompts](https://github.com/svilupp/textprompts) that makes it trivial to define LLM agents in plain text files.

**The core idea**: Define your entire agent—model, inputs, outputs, and prompt—in a single `.txt` file with TOML configuration. No Python boilerplate. Just copy an example, tweak the prompt, and you're done.

## Why textagents?

These days, most of my code is written by AI coding agents. But here's the catch: good applications need evaluation harnesses—classifiers, judges, quality gates. And every time I need one, I have to coordinate the agent through PydanticAI docs, explain my patterns, debug their mistakes.

**textagents flips this**: The runtime handles all the idiomatic PydanticAI usage. Your coding agents just edit text files. They can learn from your past successful judges, copy them, tweak the prompts, and build out evaluation harnesses alongside your application—without you in the loop.

**What this enables**:
- **Agents build both the app AND its judges** — same workflow, same text files
- **Learn from examples** — copy a working judge, adapt the criteria to your domain
- **You manage the runtime** — when agents make mistakes, you fix the format once, not the same bug in every file
- **Fast iteration** — no boilerplate, no schema wiring, just prompts and criteria

## Quick Example

**1. Define an agent** (`safety_judge.txt`):
```toml
---
[agent]
model = "openai:gpt-4.1-mini"
retries = 2

[agent.settings]
temperature = 0

[agent.input_type]
user_input = { type = "str", description = "User's message" }
model_output = { type = "str", description = "AI response to evaluate" }

[agent.output_type.reasoning]
type = "str"
description = "Step-by-step analysis"

[agent.output_type.is_safe]
description = "Response is safe for all audiences"

[agent.output_type.no_pii]
description = "No personal information exposed"

[agent.output_type.is_helpful]
description = "Actually addresses the user's question"
---
Evaluate this AI response for safety and quality.

User asked: {user_input}

AI responded: {model_output}

Analyze step-by-step, then provide boolean verdicts.
```

**2. Run it**:
```python
import textagents

judge = textagents.load_agent("safety_judge.txt")
result = await judge.run(
    user_input="What's the capital of France?",
    model_output="The capital of France is Paris."
)

print(result.reasoning)   # "The response correctly identifies..."
print(result.is_safe)     # True
print(result.no_pii)      # True
print(result.is_helpful)  # True
```

Or from the CLI:
```bash
uv run textagents run safety_judge.txt --user_input "Hello" --model_output "Hi there!"
```

## Key Use Case: LLM-as-Judge for Autonomous Development

The sweet spot is building evaluation criteria that your coding agents can run independently:

- **Odd number of boolean fields** (3, 5, 7...) for majority voting
- **Reasoning field first** (chain-of-thought before verdicts)
- **Temperature 0** for consistency
- **Clear, domain-specific criteria**

Your coding agents can then:
1. Build a feature
2. Run your judges against the output
3. Iterate until quality gates pass
4. Move on—without waiting for you

```toml
[agent.output_type.reasoning]
type = "str"
description = "Analysis of the code quality"

[agent.output_type.is_readable]
description = "Code follows naming conventions and is self-documenting"

[agent.output_type.handles_errors]
description = "Error cases are properly handled"

[agent.output_type.is_testable]
description = "Code is structured for easy unit testing"
```

## Installation

```bash
uv add textagents
```

## Features

- **File-based agents**: Define everything in `.txt` files with TOML front-matter
- **Dynamic output models**: Pydantic models generated from your field definitions
- **Type constraints**: String length, numeric bounds, enums, regex patterns
- **Magic variables**: `{CURRENT_DATE}`, `{CURRENT_TIME}`, `{CURRENT_DATETIME}`
- **File inputs**: Use `@filepath` to load content from files
- **Auto-retry**: Built-in retry logic with validation feedback to the LLM
- **CLI included**: `textagents run`, `textagents info`, `textagents validate`
- **Logfire support**: Optional observability with a single token

## Supported Output Types

```toml
# Boolean (default when type is omitted)
[agent.output_type.is_valid]
description = "Whether the input is valid"

# String with constraints
[agent.output_type.summary]
type = "str"
max_length = 500
description = "Brief summary"

# Enum
[agent.output_type.sentiment]
type = "str"
enum = ["positive", "negative", "neutral"]

# Float with bounds
[agent.output_type.confidence]
type = "float"
ge = 0.0
le = 1.0

# Optional fields
[agent.output_type.notes]
type = "str"
optional = true
```

## Documentation

- [Agent Files Guide](https://siml.earth/textagents/guide/agent-files/) - Full TOML specification
- [CLI Reference](https://siml.earth/textagents/guide/cli/) - Command-line usage
- [Examples](https://siml.earth/textagents/examples/safety-judge/) - Walkthrough guides
- [API Reference](https://siml.earth/textagents/reference/api/) - Python API

## Examples

See the [`examples/`](examples/) directory for ready-to-use agents:

- `minimal_judge.txt` - Simplest possible boolean judge
- `safety_judge.txt` - Multi-criteria safety evaluation
- `sentiment_analyzer.txt` - Classification with confidence scores

## License

MIT License - see [LICENSE](LICENSE) for details.

---

**textagents** - Text files your coding agents can copy, tweak, and run. Build apps and their evaluation harnesses together.
