Metadata-Version: 2.4
Name: domino-agui
Version: 0.4.0
Summary: AG-UI for framework agents on the Domino agent service: a ready-made agent for LangGraph, CrewAI and the Anthropic and OpenAI SDKs, and a standard-library core
License-Expression: Apache-2.0
Project-URL: Source, https://github.com/ddl-subir-m/domino-agui
Project-URL: Issues, https://github.com/ddl-subir-m/domino-agui/issues
Project-URL: Changelog, https://github.com/ddl-subir-m/domino-agui/blob/main/CHANGELOG.md
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: langgraph
Requires-Dist: ag-ui-a2ui-toolkit==0.0.5; extra == "langgraph"
Requires-Dist: ag-ui-langgraph==0.0.47; extra == "langgraph"
Requires-Dist: ag-ui-protocol==1.0.0; extra == "langgraph"
Requires-Dist: aiosqlite==0.22.1; extra == "langgraph"
Requires-Dist: annotated-doc==0.0.5; extra == "langgraph"
Requires-Dist: annotated-types==0.8.0; extra == "langgraph"
Requires-Dist: anthropic==1.17.0; extra == "langgraph"
Requires-Dist: anyio==4.15.1; extra == "langgraph"
Requires-Dist: attrs==26.1.0; extra == "langgraph"
Requires-Dist: certifi==2026.10.19; extra == "langgraph"
Requires-Dist: cffi==2.1.1; extra == "langgraph"
Requires-Dist: charset-normalizer==3.5.2; extra == "langgraph"
Requires-Dist: click==8.5.0; extra == "langgraph"
Requires-Dist: cryptography==50.0.2; extra == "langgraph"
Requires-Dist: distro==1.9.0; extra == "langgraph"
Requires-Dist: docstring-parser==0.18.0; extra == "langgraph"
Requires-Dist: fastapi==0.159.1; extra == "langgraph"
Requires-Dist: h11==0.16.0; extra == "langgraph"
Requires-Dist: httpcore==1.0.9; extra == "langgraph"
Requires-Dist: httpcore2==2.16.0; extra == "langgraph"
Requires-Dist: httpx==0.28.1; extra == "langgraph"
Requires-Dist: httpx-sse==0.4.3; extra == "langgraph"
Requires-Dist: httpx2==2.16.0; extra == "langgraph"
Requires-Dist: idna==3.20; extra == "langgraph"
Requires-Dist: jiter==0.17.0; extra == "langgraph"
Requires-Dist: jsonpatch==1.36; extra == "langgraph"
Requires-Dist: jsonpointer==3.4; extra == "langgraph"
Requires-Dist: jsonschema==4.26.0; extra == "langgraph"
Requires-Dist: jsonschema-specifications==2025.9.1; extra == "langgraph"
Requires-Dist: langchain==1.4.7; extra == "langgraph"
Requires-Dist: langchain-anthropic==1.7.6; extra == "langgraph"
Requires-Dist: langchain-core==1.6.13; extra == "langgraph"
Requires-Dist: langchain-mcp-adapters==0.3.2; extra == "langgraph"
Requires-Dist: langchain-openai==1.7.2; extra == "langgraph"
Requires-Dist: langchain-protocol==0.0.20; extra == "langgraph"
Requires-Dist: langgraph==1.2.16; extra == "langgraph"
Requires-Dist: langgraph-checkpoint==4.3.0; extra == "langgraph"
Requires-Dist: langgraph-checkpoint-sqlite==3.1.2; extra == "langgraph"
Requires-Dist: langgraph-prebuilt==1.1.1; extra == "langgraph"
Requires-Dist: langgraph-sdk==0.4.8; extra == "langgraph"
Requires-Dist: langsmith==0.14.12; extra == "langgraph"
Requires-Dist: mcp==1.30.0; extra == "langgraph"
Requires-Dist: openai==3.36.0; extra == "langgraph"
Requires-Dist: opentelemetry-api==1.45.1; extra == "langgraph"
Requires-Dist: orjson==3.13.0; extra == "langgraph"
Requires-Dist: ormsgpack==1.13.0; extra == "langgraph"
Requires-Dist: packaging==26.3; extra == "langgraph"
Requires-Dist: pycparser==3.11; extra == "langgraph"
Requires-Dist: pydantic==2.14.1; extra == "langgraph"
Requires-Dist: pydantic-core==2.50.1; extra == "langgraph"
Requires-Dist: pydantic-settings==2.16.1; extra == "langgraph"
Requires-Dist: pyjwt==2.15.1; extra == "langgraph"
Requires-Dist: python-dotenv==1.2.4; extra == "langgraph"
Requires-Dist: python-multipart==0.0.32; extra == "langgraph"
Requires-Dist: pyyaml==6.0.3; extra == "langgraph"
Requires-Dist: referencing==0.37.0; extra == "langgraph"
Requires-Dist: regex==2026.9.29; extra == "langgraph"
Requires-Dist: requests==2.34.2; extra == "langgraph"
Requires-Dist: requests-toolbelt==1.0.0; extra == "langgraph"
Requires-Dist: rpds-py==2026.9.1; extra == "langgraph"
Requires-Dist: sniffio==1.3.1; extra == "langgraph"
Requires-Dist: sqlite-vec==0.1.9; extra == "langgraph"
Requires-Dist: sse-starlette==3.5.0; extra == "langgraph"
Requires-Dist: starlette==1.9.0; extra == "langgraph"
Requires-Dist: tenacity==9.2.1; extra == "langgraph"
Requires-Dist: tiktoken==0.14.0; extra == "langgraph"
Requires-Dist: truststore==0.10.5; extra == "langgraph"
Requires-Dist: typing-extensions==4.16.0; extra == "langgraph"
Requires-Dist: typing-inspection==0.4.4; extra == "langgraph"
Requires-Dist: urllib3==2.8.0; extra == "langgraph"
Requires-Dist: uuid-utils==0.18.0; extra == "langgraph"
Requires-Dist: uvicorn==0.54.0; extra == "langgraph"
Requires-Dist: websockets==16.1.1; extra == "langgraph"
Requires-Dist: xxhash==4.0.2; extra == "langgraph"
Requires-Dist: zstandard==0.25.0; extra == "langgraph"
Provides-Extra: crewai
Requires-Dist: ag-ui-a2ui-toolkit==0.0.5; extra == "crewai"
Requires-Dist: ag-ui-crewai==1.0.0; extra == "crewai"
Requires-Dist: ag-ui-protocol==1.0.0; extra == "crewai"
Requires-Dist: aiofiles==24.1.0; extra == "crewai"
Requires-Dist: aiohappyeyeballs==2.7.1; extra == "crewai"
Requires-Dist: aiohttp==3.14.5; extra == "crewai"
Requires-Dist: aiosignal==1.4.0; extra == "crewai"
Requires-Dist: aiosqlite==0.21.0; extra == "crewai"
Requires-Dist: annotated-doc==0.0.5; extra == "crewai"
Requires-Dist: annotated-types==0.8.0; extra == "crewai"
Requires-Dist: anthropic==0.73.0; extra == "crewai"
Requires-Dist: anyio==4.15.1; extra == "crewai"
Requires-Dist: appdirs==1.4.4; extra == "crewai"
Requires-Dist: attrs==26.1.0; extra == "crewai"
Requires-Dist: bcrypt==5.0.0; extra == "crewai"
Requires-Dist: boto3==1.43.117; extra == "crewai"
Requires-Dist: botocore==1.43.117; extra == "crewai"
Requires-Dist: build==1.6.1; extra == "crewai"
Requires-Dist: cel-python==0.5.0; extra == "crewai"
Requires-Dist: certifi==2026.10.19; extra == "crewai"
Requires-Dist: cffi==2.1.1; extra == "crewai"
Requires-Dist: charset-normalizer==3.5.2; extra == "crewai"
Requires-Dist: chromadb==1.5.9; extra == "crewai"
Requires-Dist: click==8.5.0; extra == "crewai"
Requires-Dist: crewai==1.15.28; extra == "crewai"
Requires-Dist: crewai-cli==1.15.28; extra == "crewai"
Requires-Dist: crewai-core==1.15.28; extra == "crewai"
Requires-Dist: cryptography==50.0.2; extra == "crewai"
Requires-Dist: deprecation==2.1.0; extra == "crewai"
Requires-Dist: distro==1.9.0; extra == "crewai"
Requires-Dist: docstring-parser==0.18.0; extra == "crewai"
Requires-Dist: durationpy==0.11; extra == "crewai"
Requires-Dist: et-xmlfile==2.0.0; extra == "crewai"
Requires-Dist: fastapi==0.115.14; extra == "crewai"
Requires-Dist: fastuuid==0.14.0; extra == "crewai"
Requires-Dist: filelock==3.32.7; extra == "crewai"
Requires-Dist: flatbuffers==25.12.19; extra == "crewai"
Requires-Dist: frozenlist==1.8.0; extra == "crewai"
Requires-Dist: fsspec==2026.9.0; extra == "crewai"
Requires-Dist: google-re2==1.1.20251105; extra == "crewai"
Requires-Dist: googleapis-common-protos==1.75.5; extra == "crewai"
Requires-Dist: grpcio==1.84.0; extra == "crewai"
Requires-Dist: h11==0.16.0; extra == "crewai"
Requires-Dist: h2==4.4.1; extra == "crewai"
Requires-Dist: hf-xet==1.7.0; extra == "crewai"
Requires-Dist: hpack==4.2.0; extra == "crewai"
Requires-Dist: httpcore==1.0.9; extra == "crewai"
Requires-Dist: httptools==0.9.0; extra == "crewai"
Requires-Dist: httpx==0.28.1; extra == "crewai"
Requires-Dist: httpx-sse==0.4.3; extra == "crewai"
Requires-Dist: huggingface-hub==1.33.0; extra == "crewai"
Requires-Dist: hyperframe==6.1.0; extra == "crewai"
Requires-Dist: idna==3.20; extra == "crewai"
Requires-Dist: importlib-metadata==8.9.0; extra == "crewai"
Requires-Dist: importlib-resources==7.1.0; extra == "crewai"
Requires-Dist: instructor==1.15.4; extra == "crewai"
Requires-Dist: jinja2==3.1.6; extra == "crewai"
Requires-Dist: jiter==0.14.0; extra == "crewai"
Requires-Dist: jmespath==1.1.0; extra == "crewai"
Requires-Dist: json-repair==0.60.1; extra == "crewai"
Requires-Dist: json5==0.10.0; extra == "crewai"
Requires-Dist: jsonref==1.1.0; extra == "crewai"
Requires-Dist: jsonschema==4.26.0; extra == "crewai"
Requires-Dist: jsonschema-specifications==2025.9.1; extra == "crewai"
Requires-Dist: kubernetes==36.0.3; extra == "crewai"
Requires-Dist: lance-namespace==0.13.0; extra == "crewai"
Requires-Dist: lance-namespace-urllib3-client==0.13.0; extra == "crewai"
Requires-Dist: lancedb==0.30.0; extra == "crewai"
Requires-Dist: lark==1.3.1; extra == "crewai"
Requires-Dist: linkify-it-py==2.2.0; extra == "crewai"
Requires-Dist: litellm==1.105.3; extra == "crewai"
Requires-Dist: markdown-it-py==4.2.0; extra == "crewai"
Requires-Dist: markupsafe==3.0.4; extra == "crewai"
Requires-Dist: mcp==1.28.1; extra == "crewai"
Requires-Dist: mdit-py-plugins==0.6.1; extra == "crewai"
Requires-Dist: mdurl==0.1.2; extra == "crewai"
Requires-Dist: mmh3==5.3.1; extra == "crewai"
Requires-Dist: multidict==7.1.0; extra == "crewai"
Requires-Dist: numpy==2.5.4; extra == "crewai"
Requires-Dist: oauthlib==4.0.0; extra == "crewai"
Requires-Dist: onnxruntime==1.31.0; extra == "crewai"
Requires-Dist: openai==2.54.0; extra == "crewai"
Requires-Dist: openpyxl==3.1.5; extra == "crewai"
Requires-Dist: opentelemetry-api==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-exporter-http-transport==0.66b1; extra == "crewai"
Requires-Dist: opentelemetry-exporter-otlp-common==0.66b1; extra == "crewai"
Requires-Dist: opentelemetry-exporter-otlp-proto-common==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-exporter-otlp-proto-http==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-proto==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-sdk==1.45.1; extra == "crewai"
Requires-Dist: opentelemetry-semantic-conventions==0.66b1; extra == "crewai"
Requires-Dist: orjson==3.13.0; extra == "crewai"
Requires-Dist: overrides==7.7.0; extra == "crewai"
Requires-Dist: packaging==26.3; extra == "crewai"
Requires-Dist: pdfminer-six==20260107; extra == "crewai"
Requires-Dist: pdfplumber==0.11.10; extra == "crewai"
Requires-Dist: pendulum==3.3.0; extra == "crewai"
Requires-Dist: pillow==13.0.0; extra == "crewai"
Requires-Dist: platformdirs==4.13.5; extra == "crewai"
Requires-Dist: portalocker==2.7.0; extra == "crewai"
Requires-Dist: propcache==0.5.4; extra == "crewai"
Requires-Dist: protobuf==7.36.2; extra == "crewai"
Requires-Dist: pyarrow==26.0.0; extra == "crewai"
Requires-Dist: pybase64==1.5.1; extra == "crewai"
Requires-Dist: pycparser==3.11; extra == "crewai"
Requires-Dist: pydantic==2.12.5; extra == "crewai"
Requires-Dist: pydantic-core==2.41.5; extra == "crewai"
Requires-Dist: pydantic-settings==2.16.1; extra == "crewai"
Requires-Dist: pygments==2.21.0; extra == "crewai"
Requires-Dist: pyjwt==2.15.1; extra == "crewai"
Requires-Dist: pypdfium2==5.14.0; extra == "crewai"
Requires-Dist: pypika==0.51.1; extra == "crewai"
Requires-Dist: pyproject-hooks==1.3.3; extra == "crewai"
Requires-Dist: python-dateutil==2.9.0.post0; extra == "crewai"
Requires-Dist: python-dotenv==1.2.4; extra == "crewai"
Requires-Dist: python-multipart==0.0.32; extra == "crewai"
Requires-Dist: pyyaml==6.0.3; extra == "crewai"
Requires-Dist: referencing==0.37.0; extra == "crewai"
Requires-Dist: regex==2026.1.15; extra == "crewai"
Requires-Dist: requests==2.34.2; extra == "crewai"
Requires-Dist: requests-oauthlib==2.0.0; extra == "crewai"
Requires-Dist: rich==14.3.4; extra == "crewai"
Requires-Dist: rpds-py==2026.9.1; extra == "crewai"
Requires-Dist: s3transfer==0.19.3; extra == "crewai"
Requires-Dist: shellingham==1.5.4; extra == "crewai"
Requires-Dist: six==1.17.0; extra == "crewai"
Requires-Dist: sniffio==1.3.1; extra == "crewai"
Requires-Dist: sse-starlette==3.0.3; extra == "crewai"
Requires-Dist: starlette==0.46.2; extra == "crewai"
Requires-Dist: tenacity==9.2.1; extra == "crewai"
Requires-Dist: textual==8.2.8; extra == "crewai"
Requires-Dist: tiktoken==0.14.0; extra == "crewai"
Requires-Dist: tokenizers==0.23.3; extra == "crewai"
Requires-Dist: tomli==2.0.2; extra == "crewai"
Requires-Dist: tomli-w==1.1.0; extra == "crewai"
Requires-Dist: tqdm==4.70.1; extra == "crewai"
Requires-Dist: typer==0.27.3; extra == "crewai"
Requires-Dist: typing-extensions==4.16.0; extra == "crewai"
Requires-Dist: typing-inspection==0.4.4; extra == "crewai"
Requires-Dist: tzdata==2026.5; extra == "crewai"
Requires-Dist: urllib3==2.8.0; extra == "crewai"
Requires-Dist: uv==0.11.33; extra == "crewai"
Requires-Dist: uvicorn==0.54.0; extra == "crewai"
Requires-Dist: uvloop==0.23.0; extra == "crewai"
Requires-Dist: watchfiles==1.3.0; extra == "crewai"
Requires-Dist: websocket-client==1.9.2; extra == "crewai"
Requires-Dist: websockets==17.3; extra == "crewai"
Requires-Dist: yarl==1.25.1; extra == "crewai"
Requires-Dist: zipp==4.1.2; extra == "crewai"
Provides-Extra: loop
Requires-Dist: annotated-types==0.8.0; extra == "loop"
Requires-Dist: anthropic==2.1.0; extra == "loop"
Requires-Dist: anyio==4.15.1; extra == "loop"
Requires-Dist: certifi==2026.10.19; extra == "loop"
Requires-Dist: charset-normalizer==3.5.2; extra == "loop"
Requires-Dist: docstring-parser==0.18.0; extra == "loop"
Requires-Dist: h11==0.16.0; extra == "loop"
Requires-Dist: httpcore2==2.16.0; extra == "loop"
Requires-Dist: httpx2==2.16.0; extra == "loop"
Requires-Dist: idna==3.20; extra == "loop"
Requires-Dist: jiter==0.17.0; extra == "loop"
Requires-Dist: openai==3.36.0; extra == "loop"
Requires-Dist: opentelemetry-api==1.45.1; extra == "loop"
Requires-Dist: pydantic==2.14.1; extra == "loop"
Requires-Dist: pydantic-core==2.50.1; extra == "loop"
Requires-Dist: regex==2026.9.29; extra == "loop"
Requires-Dist: requests==2.34.2; extra == "loop"
Requires-Dist: sniffio==1.3.1; extra == "loop"
Requires-Dist: tiktoken==0.14.0; extra == "loop"
Requires-Dist: truststore==0.10.5; extra == "loop"
Requires-Dist: typing-extensions==4.16.0; extra == "loop"
Requires-Dist: typing-inspection==0.4.4; extra == "loop"
Requires-Dist: urllib3==2.8.0; extra == "loop"
Dynamic: license-file

# domino-agui

domino-agui is the helper library for framework agents on the Domino agent service. The agent service runs your agent's code in a
Domino Job, in a sandbox, and talks to it in [AG-UI](https://docs.ag-ui.com) 1.0. This library speaks AG-UI for your agent, and
keeps the agent contract: the model, the governed tools, the questions to a person, and the thread.

It has three parts:

- **A ready-made agent for each framework:** a LangGraph graph, a CrewAI flow, and an agent loop for the Anthropic and OpenAI SDKs.
  Your agent can be one line.
- **The helpers** that each ready-made agent is made from, for your own graph, flow or loop.
- **The core,** for a hand-written agent's handler: the server, the run's lifecycle rules, converters for the two model formats,
  and a client for the relay (the agent's governed tools). The core needs only the Python standard library.

## Install

```
pip install domino-agui
```

Python 3.10 or newer. A plain install brings no other package: the core needs only the standard library. A framework module imports
its framework only when you import that module.

For a framework agent, install a stack. A stack is the library with each package of a framework, each at one exact version: the
framework, its AG-UI bridge, the model SDKs and each package that they need. Name the framework's extra in the pip line:

```
pip install "domino-agui[langgraph]==0.4.0"
```

| Extra | Module | The stack | Python |
|---|---|---|---|
| `langgraph` | `domino_agui.langgraph` | LangGraph 1.2.16, `ag-ui-langgraph`, `langchain-openai`, `langchain-anthropic`, `langchain-mcp-adapters` | 3.12, 3.13, 3.14 |
| `crewai` | `domino_agui.crewai` | CrewAI 1.15.28, `ag-ui-crewai`, `litellm` | 3.12, 3.13 |
| `loop` | `domino_agui.loop` | the OpenAI and Anthropic SDKs | 3.12, 3.13, 3.14 |

Each extra pins every package of its stack, so the same pip line gives the same packages on a laptop and on Domino. The pins change
only with a new version of this library.

On Domino, the Environment of a framework agent must have a stack: put the pip line in the Environment's Dockerfile. Before your
agent's code runs, each Job checks the Environment's packages and Python against the stacks that the agent service accepts. A
different framework, bridge, model SDK or helper library refuses the Job. A different other package of the stack is a warning.

To see what a Job finds before any task runs, run the check command on the Environment's Python: on a laptop, in a workspace, or in
the Dockerfile after the pip line.

```
pip install "domino-agui[langgraph]==0.4.0"
python -m domino_agui check langgraph --strict
```

- It compares the Python's version with the stack's Python versions, and each package of the stack with the installed version.
  Then it imports the framework's module (`domino_agui.langgraph`), so a framework or a bridge that doesn't import is found.
- Each difference is one line with both versions and what a Job does. `REFUSED`: a named package differs (the framework, its AG-UI
  bridge, the model SDKs or this library: `stacks.NAMED`), or the Python isn't one of the stack's. `WARNING`: another package of the
  stack differs. A package that isn't installed counts as a different version. A package that the stack hasn't got isn't looked at.
- The exit code is 1 for a line that a Job refuses, or a module that doesn't import, else 0. With `--strict`, a warning gives 1 too.
- It checks this library's own stack. It can't know which stacks a deployment accepts: a Job also needs the agent service to accept
  this version of the library, on that Python.
- A Job runs its Python isolated (`python -I`). To leave out `PYTHONPATH` and your user's site-packages as a Job does, run
  `python -I -m domino_agui check langgraph`.

To use other versions of a framework's packages on a laptop, install the library with no extra and add the packages yourself:
`langgraph`, `langchain-core`, `langchain-mcp-adapters`, `httpx` and `langchain-openai` or `langchain-anthropic` for
`domino_agui.langgraph`; `crewai`, `ag-ui-crewai` and `litellm` for `domino_agui.crewai`; `openai` and `anthropic` for
`domino_agui.loop`.

## Quick start: a ready-made agent

Add one file with one line to your project. The agent's entry point is the file, a colon, and the name that the line imports:

| Framework | The file's one line | The entry point, for the file `agent/<name>.py` |
|---|---|---|
| LangGraph | `from domino_agui.langgraph import build_graph` | `agent/graph.py:build_graph` |
| CrewAI | `from domino_agui.crewai import build_flow` | `agent/flow.py:build_flow` |
| The loop (Anthropic and OpenAI SDKs) | `from domino_agui.loop import handler` | `agent/handler.py:handler` |

In the agent service, give the agent its framework (LangGraph, CrewAI or Domino AG-UI SDK for the loop), the entry point, and an
Environment that has the framework's stack.

Each ready-made agent does the same things:

- It calls the model in `AGENT_MODEL`, in the format of `AGENT_MODEL_FORMAT`, through the Job's model proxy. Each model call has an
  output limit of 16,000 tokens (`contract.MAX_TOKENS`), or the value of `AGENT_MAX_TOKENS`.
- It offers the model the agent-side tools that the relay lists, and runs them in the same AG-UI run. A denial comes back as the
  tool's answer, and the model reads it.
- It offers the client-side tools of the run, and doesn't run them. A call to one ends the AG-UI run. The agent service runs the
  tool, and the answer comes back in the next AG-UI run.
- It offers `ask_human`, the agent's tool for a question to a person. The AG-UI run ends with one interrupt, and the reply is the
  tool's result.
- It uses the run's context (the agent's system prompt, the platform's operating rules and the task brief) as the model's system
  prompt. The task's facts aren't in it: they are for your code.
- It loops until the model's answer has no tool call. That last text is the task's result.
- An empty answer (no text and no tool call) doesn't end the AG-UI run at once. The LangGraph graph and the loop give the model one
  more message, `contract.EMPTY_ANSWER`: "Your last answer was empty. Continue with the task, or give your result." They do this one
  time in an AG-UI run. A run that resumes after a reply is a new AG-UI run, so it can get its own retry. When the next answer is
  empty too, the AG-UI run ends with no result. The CrewAI flow runs its own model loop, so it has the output limit, but not this
  retry.
- An answer that stopped at the output limit isn't a finished answer. When the last answer of the LangGraph graph or the loop stopped
  at the limit, the run's last text, and so the task's result, starts with `contract.AT_LIMIT`. That note says that the answer isn't
  finished, and how to give the model a larger limit. A blank line and the cut text come after it.

## The two options: `model=` and `tools=`

Each framework module has `agent()`, which makes its ready-made agent. `build_graph`, `build_flow` and `handler` are `agent()` with no
options. Two options make another entry point of the same shape:

```python
from domino_agui.loop import agent


def risk_score(customer_id: str, days: int = 30) -> str:
    """The customer's risk score for the last `days` days."""
    return f"{customer_id}: low risk in the last {days} days"


handler = agent(tools=[risk_score])
```

**`tools=`** takes your own tools: plain functions (`def` or `async def`), with type hints and a docstring. The LangGraph module also
takes LangChain tools.

- The tool's name is the function's name, its description is the docstring's first paragraph, and its parameters come from the
  type hints: `str`, `int`, `float`, `bool`, `list`, `dict`, `list[X]`, `dict[str, X]`, `Optional[X]` (or `X | None`) and
  `Literal[...]`. A parameter with a default is optional.
- It returns a `str`, or a value that JSON can encode. An exception is the tool's answer: the model reads it, and the run goes on.
- It runs in the agent server, in the sandbox. It isn't a gateway tool, so the gateway doesn't decide or audit its calls. A tool that
  needs a decision, an approval or an audit row must be a gateway tool.
- Its name must be its own. An own tool named `ask_human`, or two own tools with one name, fail when the entry point is built. An
  own tool with the name of a gateway tool or a client-side tool fails the AG-UI run.

**`model=`** takes the framework's own model type, with the options of each model call, such as the maximum tokens:

| Module | `model=` |
|---|---|
| `domino_agui.langgraph` | A LangChain chat model: `ChatOpenAI(model=os.environ["AGENT_MODEL"], use_responses_api=False, max_tokens=1024)` |
| `domino_agui.crewai` | A LiteLLM model name, `"openai/" + os.environ["AGENT_MODEL"]`, or a `crewai.LLM(model=..., max_tokens=1024)` |
| `domino_agui.loop` | `Model(AsyncAnthropic(), max_tokens=1024)`, or an SDK client alone: `AsyncOpenAI(max_retries=5)` |

The model still goes through the Job's model proxy: the base URL and the key come from the environment. Give `ChatOpenAI`
`use_responses_api=False`, so that it uses chat completions. To limit the length of an answer, use `max_tokens`. Don't set a
temperature: a gpt-5 model can refuse a temperature other than 1.

**The output limit.** With no `model=`, each model call has the limit `contract.MAX_TOKENS`: 16,000 tokens, or the value of
`AGENT_MAX_TOKENS` (a whole number above 0, read when the library is imported). To change the limit of the platform's model in
LangGraph, use `chat_model(max_tokens=...)`:

```python
from domino_agui.langgraph import agent, chat_model

build_graph = agent(model=chat_model(max_tokens=32000))
```

For the loop, `Model(max_tokens=32000)` keeps the platform's model and changes its limit. The CrewAI flow and the loop give the limit
to an own model that sets none. A LangChain chat model of your own keeps its own limit: give it `max_tokens`, because a model alias
with no model profile can get a small default (4,096 tokens), which cuts a long answer.

## Your own LangGraph graph

An agent with its own steps builds its own graph from the helpers in `domino_agui.langgraph`: `State`, `system_prompt()`,
`chat_model()`, `relay_tools()`, and the helpers below. The entry point has the same shape, `build_graph(checkpointer)`.

- **`await finish(text)`** gives the task's result from your own last node, for example a node of plain code with no model call. It
  streams `text` as the run's last text message, and returns the state's update with the same message: the stream and the state
  have one message ID. The task's result is that text. On Python 3.10, give the node's config too: `finish(text, config)`.
- **`quiet(runnable)`** keeps the model calls of a runnable (a chat model, or `structured()`) out of the AG-UI stream: no text and
  no tool call of them is streamed. Use it for a model call whose answer your own code reads. Else the stream shows a tool call that
  no tool runs. A tool that the runnable runs with a tool call is still streamed.
- **`structured(model, schema, parse=None)`** gives a typed answer: `await structured(model, schema).ainvoke(messages)`. The schema
  is a Pydantic model class (you get an instance, which Pydantic checks), or a JSON schema dict with a `title` (you get the dict,
  with each key that the schema's top level requires). The model gets the schema as its one tool, and the tool choice isn't forced:
  the newest Claude models refuse a forced tool choice, and LangChain's `with_structured_output` forces one for a model alias.
  - When the answer doesn't fit, the model is asked one time again, with the same messages and a short note of why. An answer
    doesn't fit when it has no call of the tool, the call doesn't fit the schema, it has no text and no tool call, or it stopped at
    the output limit. Then `structured()` raises `Unusable`, and `str()` of it says why.
  - A refusal (`stop_reason` refusal, or `finish_reason` content_filter) raises `Refused` (an `Unusable`) at once, with no more
    try: the same request is refused again.
  - `parse` is your own step on the value: it returns the value to give, or raises `ValueError` with why it doesn't fit. The model
    is then asked again too.
  - To keep it out of the stream, put `quiet()` outside: `quiet(structured(model, schema))`.

A graph with two nodes: the model's verdict, which the graph reads itself, then the task's result from plain code.

```python
from typing import Literal

from langchain_core.messages import HumanMessage
from langgraph.graph import END, START, StateGraph
from pydantic import BaseModel

from domino_agui.langgraph import State, Unusable, chat_model, finish, quiet, structured, system_prompt


class Verdict(BaseModel):
    """The verdict on the change: approve or reject, and why."""
    verdict: Literal["approve", "reject"]
    reason: str


class Review(State, total=False):
    verdict: dict


async def judge(state: Review):
    ask = quiet(structured(chat_model(), Verdict))
    try:
        got = await ask.ainvoke(system_prompt(state) + state["messages"] + [HumanMessage("Give your verdict.")])
    except Unusable as e:   # also a refusal (Refused)
        return {"verdict": {"verdict": "could not check", "reason": str(e)}}
    return {"verdict": got.model_dump()}


async def report(state: Review):
    v = state["verdict"]
    return await finish(f"Verdict: {v['verdict']}. {v['reason']}")


def build_graph(checkpointer):
    g = StateGraph(Review)
    g.add_node("judge", judge)
    g.add_node("report", report)
    g.add_edge(START, "judge")
    g.add_edge("judge", "report")
    g.add_edge("report", END)
    return g.compile(checkpointer=checkpointer)
```

## A hand-written handler on the core

A handler is `async def handler(run)`. `run` has the AG-UI run's inputs (`run.messages`, the full history; `run.state`;
`run.resume`; `run.client_tools`; `run.context`) and its outputs (`run.text()`, `run.tool_call()`, `run.client_tool_call()`,
`run.state_snapshot()`, `run.interrupt()`, `run.finish()`). The library keeps the lifecycle rules: it sends `RUN_STARTED` first and
one final event last, and a handler that raises ends the run with `RUN_ERROR`.

This handler owns its loop. It calls an OpenAI-compatible model through the converters, and runs the gateway tools through the relay:

```python
from openai import AsyncOpenAI

from domino_agui import contract, convert

client = AsyncOpenAI()   # the base URL and the key come from the environment


async def handler(run):
    client_side = {t["name"] for t in run.client_tools}
    tools = run.client_tools + [t for t in await contract.relay_tools() if t["name"] not in client_side]
    system = contract.system_prompt(run.context)
    history = ([{"id": "context", "role": "system", "content": system}] if system else []) + run.messages
    while True:
        completion = await client.chat.completions.create(model=contract.model_alias(), **convert.to_openai(history, tools))
        answer = convert.from_openai(completion)
        history.append(answer.message())
        if answer.text:
            run.text(answer.text)
        for call in answer.tool_calls:
            if call.name in client_side:   # the agent service runs it: the call stays open, and the run ends
                run.client_tool_call(call.name, call.arguments, tool_call_id=call.id)
            else:   # a gateway tool, through the relay: a denial is an error result, not an exception
                result = await contract.call_tool(call.name, call.arguments)
                run.tool_call(call.name, call.arguments, result.text, tool_call_id=call.id)
                history.append(result.message(call.id))
        if not answer.tool_calls or any(c.name in client_side for c in answer.tool_calls):
            return   # the last text is the task's result, or the client-side calls stay open
```

For the Anthropic SDK, use `convert.to_anthropic()` and `convert.from_anthropic()` with `client.messages.create()`. To ask a person,
end the run with `run.interrupt(question)`: the answer is `run.resume` in the next run. The ready-made loop, `domino_agui.loop`, has
the whole loop with `ask_human`, and its helpers (`call_model()`, `ask_human()`, `answered_question()`) are public.

To try a handler on a laptop, serve it on a Unix socket and post an AG-UI run to it:

```
python -c 'import domino_agui, my_agent; domino_agui.serve(my_agent.handler, "agent.sock")' &
curl -sN --unix-socket agent.sock http://agent/agent -H 'Content-Type: application/json' \
  -d '{"threadId": "t1", "runId": "r1", "messages": [{"id": "m1", "role": "user", "content": "Say hello in five words."}]}'
```

The answer is the run's AG-UI events, one per `data:` line.

## The task's facts and gateway calls from your code

Your own graph, flow or handler can read the task's facts, and call a gateway tool from its code, with no parse of the task brief.
The agent service sends the facts in each AG-UI run, as JSON in a second context item. `contract.task(context)` gives them as a
dict:

```python
from domino_agui import contract

facts = contract.task(run.context)   # LangGraph: state["ag-ui"]["context"]; CrewAI: state.context
bundle = next(r for r in facts["resources"] if r["type"] == "bundle")
docs = next(r for r in facts["resources"] if r["from"] == "pinned")   # a resource of the trigger, with its mount
```

- The facts have `version` 1, `task` (`id`, `key`, `title`), `project` (`id`, `name`, `owner`), `resources` (each with `type`,
  `id`, `name`, `access`, `mount` and `from`), `inputs`, `trigger` (`id`, `type`, `name`; None for a direct run), `payload` (the
  trigger's payload) and `payloadOmitted` (True when the payload was too large to send). The docstring of `contract.task()` says what
  each one holds.
- A new field is an addition to version 1. Facts of another version raise a `ValueError` that names the version.
- Outside a Job, or with an agent service that doesn't send them, there are no facts: `task()` gives None.
- `contract.system_prompt()` leaves the facts out. The task brief gives the model the same facts as text.

To call a gateway tool from your code, use `contract.call_json()` for the JSON of its answer, or `contract.gateway_call()` for its
`ToolResult`:

```python
found = await contract.call_json("get_bundle", {"bundleId": bundle["id"]})   # a dict

result = await contract.gateway_call("get_bundle", {"bundleId": bundle["id"]})
if not result.is_error:   # is_error: a denial, or a call that failed
    found = result.json()
```

- Each call goes through the gateway's decision and audit, as the model's calls do.
- `ToolResult.json()` gives the JSON at the start of the answer. A note for the model can follow the JSON on the next lines
  (`run_job` adds one): `json()` leaves it out. An answer that isn't JSON raises a `ValueError`. A denial is JSON too, so look at
  `is_error` first.
- `call_json()` raises `contract.ToolError` for a denial or a failed call. Its text has the gateway's text, `e.name` is the tool and
  `e.result` is the `ToolResult`.
- Outside a Job (no `AGENT_SERVICE_URL`), there is no relay: `gateway_call()` and `call_json()` raise a `RelayError` that names
  `AGENT_SERVICE_URL`. In a unit test, give your code a stand-in for the call.

## The agent contract

The platform sets these variables in the agent server's environment, in a Job:

| Variable | What it is |
|---|---|
| `AGENT_MODEL` | The model's alias at the model gateway. The ready-made agents call this model. |
| `AGENT_MODEL_FORMAT` | The model's format: `anthropic` (Anthropic Messages), else `openai` (OpenAI chat completions, which OpenAI-compatible models speak too). |
| `AGENT_SERVICE_URL` | The agent service. Its relay is MCP at `$AGENT_SERVICE_URL/mcp`: the agent-side tools. Not set outside a Job, so there are no agent-side tools on a laptop. |
| `SESSION_TOKEN` | The relay's bearer token for this Job. |

You can set one more variable in the Job's environment, for example as a project's environment variable: `AGENT_MAX_TOKENS`, the
output limit of the ready-made agents' model calls, in tokens (`contract.MAX_TOKENS`, 16,000 when it isn't set). The sandbox keeps
`AGENT_*` variables for the agent server. A value that isn't a whole number above 0 fails at the import, with an error that names it.

`AGENT_FRAMEWORK` (`contract.FRAMEWORK_ENV`) is set only in an Environment built from a framework image that the agent service made
before the stacks: an `ENV` line in its Dockerfile names the image's framework. There, a framework module of another framework fails
at its import, with an error that names the Environment to use. An Environment built with a stack's pip line doesn't set it, and a
laptop doesn't either, so no framework module checks it.

The platform also sets each model SDK's base URL and key, so that each model call goes through the Job's model proxy and the model
gateway. On a laptop, set `AGENT_MODEL`, `AGENT_MODEL_FORMAT` and your provider's key.

The relay's rules:

- Each relay call goes through the gateway's decision and audit. A denial or a failed call is a result with `is_error`, for the
  model to read. A `RelayError` means that the relay itself failed.
- The relay client of the ready-made agents connects within 30 seconds (`contract.CONNECT_TIMEOUT`), and waits up to 300 seconds
  for each answer (`contract.READ_TIMEOUT`). A relay call can stay open for up to 45 seconds, so keep a read timeout of 60 seconds or
  more. `Relay(url=None, token=None, *, timeout=120, read_timeout=None)`: `timeout` is the time to connect, and to wait for each
  answer unless `read_timeout` is given.
- The relay client connects to the relay directly, never through the egress proxy in `HTTP_PROXY`.

The run's rules:

- Each AG-UI run brings the full history and the last state. The agent server keeps nothing between runs: the agent service keeps
  the thread.
- A run ends with one interrupt at most, and an interrupt is a question, never an approval. A resume is `resolved`, with the reply
  text, or `cancelled`, when the answer came after the question's `expiresAt`.
- A run with open client-side calls ends as a success that names them. Their answers are tool messages in the next run.
- The agent server listens on a Unix socket: `POST /agent` takes a `RunAgentInput` and answers with server-sent events, and
  `GET /health` answers `{ok, framework, versions}`.

## Versions

The versions follow [semantic versioning](https://semver.org). The changes are in
[CHANGELOG.md](https://github.com/ddl-subir-m/domino-agui/blob/main/CHANGELOG.md). A stack has the library's version: the
LangGraph stack 0.4.0 is `pip install "domino-agui[langgraph]==0.4.0"`, and its pins change only in a new version.

## Report a problem

Open an issue on [GitHub](https://github.com/ddl-subir-m/domino-agui/issues). For a security problem, don't open an issue: read
[SECURITY.md](https://github.com/ddl-subir-m/domino-agui/blob/main/SECURITY.md).

## The checks

The checks need only the standard library. Most of them run against the installed package; `check_text.py` reads the repo's text:

```
pip install .
python tests/check_domino_agui.py
python tests/check_docstrings.py
python tests/check_release_tag.py
python tests/check_stacks.py
python tests/check_stack_command.py
python tests/check_text.py
```

`check_stacks.py` has two slow parts, which need the network. `STACK_INSTALL=<extra>` builds the wheel, installs the extra into a new
venv on Linux, finds the stack's lock, and runs `python -m domino_agui check <extra> --strict` in that venv. `STACK_LOCK=1` runs the
stacks' generator. The CI runs both. `check_stack_command.py` runs the check command in new venvs that have the installed package and
a written METADATA for each package of a stack, at its version or at another one.

The extras' pins are the locks in `stacks/`, one for each extra. `scripts/stacks.py lock` makes them with uv: it resolves each stack
for x86_64 Linux on each Python version of the stack, stops when a Python version gives another lock, and writes the extras in
`pyproject.toml` from the locks. To change a stack, change its requirements in `scripts/stacks.py`, run the generator, and commit
the locks and `pyproject.toml`.

## License

Apache License 2.0. Copyright Domino Data Lab, Inc. See [LICENSE](https://github.com/ddl-subir-m/domino-agui/blob/main/LICENSE)
and [NOTICE](https://github.com/ddl-subir-m/domino-agui/blob/main/NOTICE).
