# Agently

> Python framework for AI service backends with output contracts, observable actions and event-driven workflows

- Category: App Orchestration / App Frameworks
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/AgentEra/Agently
- Website: https://agently.tech
- Canonical page: https://ai-tldr.dev/tools/agently/

## In short

Agently is an open-source Python framework, maintained by AgentEra, for building the backend of an AI application. It sits in the App Frameworks category of the App Orchestration tools and is open-source, written in Python and licensed Apache-2.0. To get started: install.

## Overview

Agently is an open-source Python framework, maintained by AgentEra, for building the backend of an AI application. Its focus is the engineering layer around model calls: a request is composed from named prompt slots (role, info, instruct, input, output), the expected result shape is declared with `.output(...)`, and the framework owns parsing, required-key checks, retries and validation handlers instead of relying only on a provider's native JSON mode. The same request contract sits in front of every model provider, so the project's stated goal is that swapping DeepSeek for a local Ollama model or Claude does not change what downstream business code receives.

On top of that request layer sit several opt-in pieces. Actions are model-callable capabilities — decorated local functions, MCP servers, built-in Search and Browse packages, and managed Python, shell, Node.js and SQLite runtimes — and every call leaves a structured action log. TriggerFlow is the workflow layer: an event- and signal-driven engine with branching, `for_each` fan-out, pause/resume, human-in-the-loop events, save/load and close snapshots. Dynamic Task turns a model- or app-generated DAG into a validated task graph that runs on TriggerFlow, and Session keeps bounded multi-turn memory.

Agently also exposes structure while a model is still streaming: its `instant` mode emits events per output field, so a UI or SSE route can render a partial structured answer before the final token. A `FastAPIHelper` publishes agents, requests and TriggerFlow executions over POST, SSE or WebSocket, and the optional `agently-devtools` package adds a local console for runtime observation, evaluations and a playground. The core is Apache-2.0 licensed under an open-core model, requires Python 3.10 or newer, and is published on PyPI as `agently`.

## What it does

- Contract-first structured output — `.output(...)` schemas with required fields, `ensure_keys`, parser feedback, retries and validation handlers, also expressible in YAML or JSON prompt files
- One request contract across providers: an OpenAI-compatible requester (OpenAI, DeepSeek, Qwen, Ollama, Kimi, GLM and others) plus an Anthropic-compatible requester, with model pools and API-key pools for failover
- `instant` structured streaming that emits an event per field path as the model generates, for live UIs and SSE routes
- Actions runtime covering decorated Python functions, MCP servers, built-in Search/Browse, and managed Python, shell, Node.js and SQLite resources, with structured action logs
- TriggerFlow event-driven workflows with branching, fan-out, external events, pause/resume, persistence and close snapshots, plus Dynamic Task for validated DAG plans
- Service and tooling surfaces: FastAPIHelper for POST/SSE/WebSocket exposure and the optional agently-devtools console for observation and evaluation

## Getting started

Agently is a Python package (Python 3.10+). Any OpenAI-compatible endpoint works as the model; the README's quickstart uses DeepSeek's hosted API or a local Ollama model.

1. Install

   Install or upgrade the package from PyPI.

```bash
pip install -U agently
```

2. Configure a model and ask for structured output

   Point Agently at an OpenAI-compatible endpoint, create an agent, and declare the result shape with .output(). The third tuple item marks a field as required.

```python
from agently import Agently

Agently.set_settings(
    "OpenAICompatible",
    {
        "base_url": "https://api.deepseek.com/v1",
        "model": "deepseek-v4-flash",
        "api_key": "${ENV.DEEPSEEK_API_KEY}",
        "model_type": "chat",
    },
)

agent = Agently.create_agent()

result = (
    agent
    .input("Introduce Python in one sentence and state three distinct strengths.")
    .output({
        "intro": (str, "one sentence", True),
        "strengths": {
            "first": (str, "first strength", True),
            "second": (str, "second strength", True),
            "third": (str, "third strength", True),
        },
    })
    .get_result()
)

print(result.get_data())
```

3. Or run against a local model

   Swap only the provider settings to use Ollama; the request code stays the same.

```python
# ollama pull qwen2.5:7b
Agently.set_settings(
    "OpenAICompatible",
    {
        "base_url": "http://127.0.0.1:11434/v1",
        "model": "qwen2.5:7b",
        "api_key": "ollama",
        "model_type": "chat",
    },
)
```

4. Give the agent an action

   Decorate a function with @agent.action_func and register it; the model can call it and the calls are recorded in the result's action logs.

```python
@agent.action_func
def calculate_total(price: float, quantity: int) -> float:
    """Calculate an order total."""
    return price * quantity

agent.use_actions(calculate_total)

result = agent.input("Use the available action to calculate 19.5 * 4, then explain the result.").get_result()
print(result.get_text())
```

5. Observe runs with DevTools (optional)

   Install the companion devtools package, start its local console, and attach an ObservationBridge in your app to see each run.

```bash
pip install -U agently agently-devtools
agently-devtools start
```

## When to use it

- Reach for it when an AI-backed API must return a stable JSON shape even as you switch between hosted and local models
- Reach for it to stream partially-filled structured answers into a chat UI or SSE endpoint before the model finishes
- Reach for it when a multi-step AI process needs branching, fan-out, human approval pauses and restart-safe state in plain Python
- Reach for it to let a model operate business objects through a constrained set of logged actions rather than free-form tool calls
