graticor 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graticor-0.2.0.dist-info/METADATA +1371 -0
- graticor-0.2.0.dist-info/RECORD +59 -0
- graticor-0.2.0.dist-info/WHEEL +4 -0
- graticor-0.2.0.dist-info/entry_points.txt +2 -0
- pac_agents/__init__.py +82 -0
- pac_agents/__main__.py +7 -0
- pac_agents/_aio.py +148 -0
- pac_agents/_canonical.py +38 -0
- pac_agents/_log.py +37 -0
- pac_agents/_state.py +198 -0
- pac_agents/_version.py +3 -0
- pac_agents/adapters.py +263 -0
- pac_agents/agents.py +1026 -0
- pac_agents/architecture/__init__.py +113 -0
- pac_agents/architecture/_adk.py +103 -0
- pac_agents/architecture/_crewai.py +163 -0
- pac_agents/architecture/_graph.py +372 -0
- pac_agents/architecture/_langgraph.py +217 -0
- pac_agents/architecture/_llamaindex.py +235 -0
- pac_agents/architecture/_openai_agents.py +132 -0
- pac_agents/architecture/_pydantic_ai.py +70 -0
- pac_agents/architecture/_raw.py +61 -0
- pac_agents/architecture/_smolagents.py +65 -0
- pac_agents/attributes.py +229 -0
- pac_agents/cli.py +621 -0
- pac_agents/cli_config.py +892 -0
- pac_agents/cli_keys.py +368 -0
- pac_agents/cli_sandbox.py +197 -0
- pac_agents/client.py +247 -0
- pac_agents/config.py +221 -0
- pac_agents/context.py +270 -0
- pac_agents/define.py +603 -0
- pac_agents/errors.py +54 -0
- pac_agents/evals.py +421 -0
- pac_agents/guard.py +145 -0
- pac_agents/kb.py +292 -0
- pac_agents/memory.py +137 -0
- pac_agents/py.typed +0 -0
- pac_agents/ref.py +175 -0
- pac_agents/run_api.py +326 -0
- pac_agents/runs.py +524 -0
- pac_agents/sandbox/__init__.py +16 -0
- pac_agents/sandbox/assets.py +120 -0
- pac_agents/sandbox/backends/__init__.py +11 -0
- pac_agents/sandbox/backends/base.py +199 -0
- pac_agents/sandbox/backends/docker.py +745 -0
- pac_agents/sandbox/backends/process.py +672 -0
- pac_agents/sandbox/browserctl.py +240 -0
- pac_agents/sandbox/browserd.py +726 -0
- pac_agents/sandbox/checks.py +134 -0
- pac_agents/sandbox/daemon.py +735 -0
- pac_agents/sandbox/idempotency.py +138 -0
- pac_agents/sandbox/protocol.py +169 -0
- pac_agents/sandbox/runner.py +122 -0
- pac_agents/sandbox/state.py +142 -0
- pac_agents/spans.py +541 -0
- pac_agents/tracing.py +1075 -0
- pac_agents/worker.py +503 -0
- pac_agents/workflows.py +581 -0
|
@@ -0,0 +1,1371 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: graticor
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Trace, configure, serve and evaluate Python agents on Graticor.
|
|
5
|
+
Project-URL: Homepage, https://graticor.com
|
|
6
|
+
Project-URL: Documentation, https://app.graticor.com/docs/python
|
|
7
|
+
Author: Graticor
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Keywords: agents,evaluation,langgraph,llm,openinference,opentelemetry,tracing
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Requires-Dist: httpx>=0.27
|
|
21
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27
|
|
22
|
+
Requires-Dist: opentelemetry-sdk>=1.27
|
|
23
|
+
Provides-Extra: agno
|
|
24
|
+
Requires-Dist: openinference-instrumentation-agno>=0.1.0; extra == 'agno'
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: langchain-openai>=0.2; extra == 'all'
|
|
27
|
+
Requires-Dist: openai>=1.40; extra == 'all'
|
|
28
|
+
Requires-Dist: openinference-instrumentation-agno>=0.1.0; extra == 'all'
|
|
29
|
+
Requires-Dist: openinference-instrumentation-anthropic>=0.1.0; extra == 'all'
|
|
30
|
+
Requires-Dist: openinference-instrumentation-autogen-agentchat>=0.1.0; (python_version >= '3.10') and extra == 'all'
|
|
31
|
+
Requires-Dist: openinference-instrumentation-bedrock>=0.1.0; extra == 'all'
|
|
32
|
+
Requires-Dist: openinference-instrumentation-crewai>=0.1.0; extra == 'all'
|
|
33
|
+
Requires-Dist: openinference-instrumentation-dspy>=0.1.0; extra == 'all'
|
|
34
|
+
Requires-Dist: openinference-instrumentation-google-adk>=0.1.0; extra == 'all'
|
|
35
|
+
Requires-Dist: openinference-instrumentation-groq>=0.1.0; extra == 'all'
|
|
36
|
+
Requires-Dist: openinference-instrumentation-langchain>=0.1.28; extra == 'all'
|
|
37
|
+
Requires-Dist: openinference-instrumentation-litellm>=0.1.0; extra == 'all'
|
|
38
|
+
Requires-Dist: openinference-instrumentation-llama-index>=3.0; extra == 'all'
|
|
39
|
+
Requires-Dist: openinference-instrumentation-mistralai>=0.1.0; extra == 'all'
|
|
40
|
+
Requires-Dist: openinference-instrumentation-openai-agents>=0.1.0; extra == 'all'
|
|
41
|
+
Requires-Dist: openinference-instrumentation-openai>=0.1.14; extra == 'all'
|
|
42
|
+
Requires-Dist: openinference-instrumentation-pydantic-ai>=0.1.0; extra == 'all'
|
|
43
|
+
Requires-Dist: openinference-instrumentation-smolagents>=0.1.0; (python_version >= '3.10') and extra == 'all'
|
|
44
|
+
Provides-Extra: anthropic
|
|
45
|
+
Requires-Dist: openinference-instrumentation-anthropic>=0.1.0; extra == 'anthropic'
|
|
46
|
+
Provides-Extra: autogen
|
|
47
|
+
Requires-Dist: openinference-instrumentation-autogen-agentchat>=0.1.0; (python_version >= '3.10') and extra == 'autogen'
|
|
48
|
+
Provides-Extra: bedrock
|
|
49
|
+
Requires-Dist: openinference-instrumentation-bedrock>=0.1.0; extra == 'bedrock'
|
|
50
|
+
Provides-Extra: crewai
|
|
51
|
+
Requires-Dist: openinference-instrumentation-crewai>=0.1.0; extra == 'crewai'
|
|
52
|
+
Provides-Extra: dev
|
|
53
|
+
Requires-Dist: langchain-openai>=0.2; extra == 'dev'
|
|
54
|
+
Requires-Dist: langgraph>=0.2; extra == 'dev'
|
|
55
|
+
Requires-Dist: openai>=1.40; extra == 'dev'
|
|
56
|
+
Requires-Dist: openinference-instrumentation-langchain>=0.1.28; extra == 'dev'
|
|
57
|
+
Requires-Dist: openinference-instrumentation-openai>=0.1.14; extra == 'dev'
|
|
58
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
59
|
+
Provides-Extra: dspy
|
|
60
|
+
Requires-Dist: openinference-instrumentation-dspy>=0.1.0; extra == 'dspy'
|
|
61
|
+
Provides-Extra: google-adk
|
|
62
|
+
Requires-Dist: openinference-instrumentation-google-adk>=0.1.0; extra == 'google-adk'
|
|
63
|
+
Provides-Extra: groq
|
|
64
|
+
Requires-Dist: openinference-instrumentation-groq>=0.1.0; extra == 'groq'
|
|
65
|
+
Provides-Extra: langchain
|
|
66
|
+
Requires-Dist: langchain-openai>=0.2; extra == 'langchain'
|
|
67
|
+
Requires-Dist: openinference-instrumentation-langchain>=0.1.28; extra == 'langchain'
|
|
68
|
+
Provides-Extra: litellm
|
|
69
|
+
Requires-Dist: openinference-instrumentation-litellm>=0.1.0; extra == 'litellm'
|
|
70
|
+
Provides-Extra: llama-index
|
|
71
|
+
Requires-Dist: openinference-instrumentation-llama-index>=3.0; extra == 'llama-index'
|
|
72
|
+
Provides-Extra: mistral
|
|
73
|
+
Requires-Dist: openinference-instrumentation-mistralai>=0.1.0; extra == 'mistral'
|
|
74
|
+
Provides-Extra: openai
|
|
75
|
+
Requires-Dist: openai>=1.40; extra == 'openai'
|
|
76
|
+
Requires-Dist: openinference-instrumentation-openai>=0.1.14; extra == 'openai'
|
|
77
|
+
Provides-Extra: openai-agents
|
|
78
|
+
Requires-Dist: openinference-instrumentation-openai-agents>=0.1.0; extra == 'openai-agents'
|
|
79
|
+
Provides-Extra: pydantic-ai
|
|
80
|
+
Requires-Dist: openinference-instrumentation-pydantic-ai>=0.1.0; extra == 'pydantic-ai'
|
|
81
|
+
Provides-Extra: smolagents
|
|
82
|
+
Requires-Dist: openinference-instrumentation-smolagents>=0.1.0; (python_version >= '3.10') and extra == 'smolagents'
|
|
83
|
+
Description-Content-Type: text/markdown
|
|
84
|
+
|
|
85
|
+
# graticor: the Python SDK of Graticor
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install graticor
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import pac_agents as pac
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The Python SDK of the **Graticor Agents** platform. Write your agent in any framework (LangGraph,
|
|
96
|
+
CrewAI, the OpenAI Agents SDK, LlamaIndex, Google ADK, Pydantic AI, smolagents, plain code) and the
|
|
97
|
+
SDK connects it to Graticor. It installs as `graticor`, imports as `pac_agents`, and its command is
|
|
98
|
+
`pac-agents`. The import and the command keep the platform's earlier name, so existing code and
|
|
99
|
+
`PAC_*` settings work unchanged. Documentation: <https://app.graticor.com/docs/python>.
|
|
100
|
+
|
|
101
|
+
- **Tracing.** Every LLM call, tool call, retrieval and agent step is sent to Graticor over OpenTelemetry
|
|
102
|
+
(OTLP), with tokens, cost and the prompts. Installed frameworks are instrumented automatically.
|
|
103
|
+
- **Models from the console.** Your code asks the Graticor model router for `model:<agent>/<slot>`; the
|
|
104
|
+
console decides which model that is: a Graticor deployment, a provider you connected (OpenAI,
|
|
105
|
+
Anthropic, Mistral...), or the free Simulated model. Swap models without a deploy.
|
|
106
|
+
- **Config from the console.** Instructions, typed params and model slots live in the console,
|
|
107
|
+
with a draft for development and published versions for production.
|
|
108
|
+
- **Architecture.** `agent.register(obj)` sends the graph of your agent (nodes, tools, handoffs);
|
|
109
|
+
Graticor draws it and overlays live traces on it.
|
|
110
|
+
- **Runs from Graticor.** `agent.serve()` turns your process into a worker: the playground, schedules,
|
|
111
|
+
webhooks and evaluations run your code.
|
|
112
|
+
- **Knowledge, memory, evaluations.** Search Graticor knowledge bases with citations, keep long-term
|
|
113
|
+
memory per end user, and gate CI on evaluation scores.
|
|
114
|
+
- **Config as code.** Define hosted and workflow agents in Python (`pac.define(...)`), keep them in
|
|
115
|
+
your repository, and push them (`pac-agents push`); pull any agent as a file or as Python, and
|
|
116
|
+
pull, diff and push a workflow's steps (`pac-agents workflow ...`).
|
|
117
|
+
- **Runs and outcomes.** Start runs of any agent with your key (`pac.runs.create`), or with the
|
|
118
|
+
agent's own API key for your customers' traffic (`pac.AgentApi`), and report what each run was
|
|
119
|
+
worth (`pac.outcome`).
|
|
120
|
+
- **Memory review and the sandbox daemon.** Review what agents proposed to remember
|
|
121
|
+
(`pac.memories`), and run Graticor agents' sandboxes on your own Linux machines (`pac-agents sandbox`).
|
|
122
|
+
|
|
123
|
+
Tracing never breaks your application: with Graticor down, spans are dropped and config pulls fall back
|
|
124
|
+
to the last good copy, each with one warning on the `pac_agents` logger.
|
|
125
|
+
|
|
126
|
+
## Status (as of 2026-11-23)
|
|
127
|
+
|
|
128
|
+
- **Package.** `graticor` 0.2.0 on PyPI (`src/pac_agents/_version.py`), imported as `pac_agents`,
|
|
129
|
+
with the command `pac-agents` (`pyproject.toml`). Python 3.9 or later. The import and the command
|
|
130
|
+
keep the old "PAC" prefix, like the `PAC_*` variables, so existing setups keep working.
|
|
131
|
+
- **Published by CI.** `.github/workflows/publish-python.yml` runs the tests, builds the wheel and the
|
|
132
|
+
sdist, and publishes them to PyPI with Trusted Publishing (no PyPI token is stored anywhere).
|
|
133
|
+
- **Offered by a server only when its operator sets it up.** A server offers the wheel only when
|
|
134
|
+
`PAC_SANDBOX_DAEMON_WHEEL` points at a built wheel. The production files in this repository
|
|
135
|
+
(`deploy/prod/compose.yaml`, `deploy/prod/.env.example`) neither set it nor mount a wheel, so a
|
|
136
|
+
server deployed from them offers no Python package yet; Connect code then shows the checkout
|
|
137
|
+
line. The local Docker setup mounts `dist/daemon` read-only for it (`deploy/local/compose.yaml`).
|
|
138
|
+
- **Built.** Everything this README describes is in the package. The tests (42 files in `tests/`)
|
|
139
|
+
run against a faked Graticor API ([Development](#development)). The publishing workflow runs them
|
|
140
|
+
on Python 3.9, 3.12 and 3.13 before each release; `.github/workflows/ci.yml` runs the TypeScript SDK's.
|
|
141
|
+
- **Only Python code agents have a worker.** The TypeScript SDK (`sdks/typescript`) has no worker
|
|
142
|
+
yet, so the playground, schedules and evaluations can run Python code only.
|
|
143
|
+
- **Some features depend on the server's settings**:
|
|
144
|
+
- `platform-claude` needs the operator to turn it on ([How model assignment works](#how-model-assignment-works));
|
|
145
|
+
- a Graticor deployment answers with a real model only when it was deployed with
|
|
146
|
+
`PAC_DEPLOY_EXECUTE=1`; otherwise it is a dry run and answers through the simulator;
|
|
147
|
+
- knowledge search is always lexical, and semantic too once an embedding model is set up;
|
|
148
|
+
- the sandbox daemon needs the wheel and an https `PAC_PUBLIC_API_URL` on the server
|
|
149
|
+
([The sandbox daemon](#the-sandbox-daemon-linux-or-wsl)).
|
|
150
|
+
|
|
151
|
+
## Contents
|
|
152
|
+
|
|
153
|
+
- [Status (as of 2026-11-23)](#status-as-of-2026-11-23)
|
|
154
|
+
- [Install](#install)
|
|
155
|
+
- [Quickstart (5 minutes)](#quickstart-5-minutes)
|
|
156
|
+
- [How model assignment works](#how-model-assignment-works)
|
|
157
|
+
- [Tracing](#tracing)
|
|
158
|
+
- [Registering the architecture](#registering-the-architecture)
|
|
159
|
+
- [Serving: the worker](#serving-the-worker)
|
|
160
|
+
- [Params](#params)
|
|
161
|
+
- [Knowledge bases](#knowledge-bases)
|
|
162
|
+
- [Memory](#memory)
|
|
163
|
+
- [Guardrail checks](#guardrail-checks)
|
|
164
|
+
- [Evaluations and CI gates](#evaluations-and-ci-gates)
|
|
165
|
+
- [Config as code](#config-as-code)
|
|
166
|
+
- [Workflow files](#workflow-files)
|
|
167
|
+
- [Runs and outcomes](#runs-and-outcomes)
|
|
168
|
+
- [Start runs with an agent API key](#start-runs-with-an-agent-api-key)
|
|
169
|
+
- [Reviewing memories](#reviewing-memories)
|
|
170
|
+
- [Configuration reference](#configuration-reference)
|
|
171
|
+
- [Command line](#command-line)
|
|
172
|
+
- [The sandbox daemon (Linux or WSL)](#the-sandbox-daemon-linux-or-wsl)
|
|
173
|
+
- [Examples](#examples)
|
|
174
|
+
- [Troubleshooting](#troubleshooting)
|
|
175
|
+
- [Development](#development)
|
|
176
|
+
|
|
177
|
+
## Install
|
|
178
|
+
|
|
179
|
+
Python 3.9 or later. The package is on PyPI as **`graticor`** (it was called `pac-agents` before it
|
|
180
|
+
was published: never `pip install pac-agents`, a name Graticor does not own on PyPI).
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
pip install graticor # the core: tracing, config, runs, knowledge, memory, evaluations
|
|
184
|
+
pip install "graticor[langchain]" # with a framework's tracing (extras below)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Two other ways in, for a server that is not connected to PyPI or for a development copy:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# From your Graticor server, when its operator offers the package (Connect code shows the exact line,
|
|
191
|
+
# with its sha256; pip checks it):
|
|
192
|
+
pip install "graticor[langchain] @ https://<your Graticor>/api/agents/sdk/packages/<token>/graticor-0.2.0-py3-none-any.whl#sha256=<sha256>"
|
|
193
|
+
|
|
194
|
+
# From a Graticor checkout:
|
|
195
|
+
pip install -e "<path to your Graticor checkout>/sdks/python[langchain]"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The server offers the same wheel it serves to sandbox daemons. The operator builds it with
|
|
199
|
+
`node scripts/build-daemon-wheel.mjs` (it writes `dist/daemon/graticor-0.2.0-py3-none-any.whl` and
|
|
200
|
+
prints its sha256) and points `PAC_SANDBOX_DAEMON_WHEEL` at it. `GET /api/agents/sdk/packages` lists
|
|
201
|
+
what a server offers (`apps/api/src/agents/devx/sdkPackages.ts`). The download link carries a token
|
|
202
|
+
derived from the server's `PAC_SECRET`: it does not expire, but it changes when `PAC_SECRET`
|
|
203
|
+
changes. Without the setting the server offers no package, and Connect code shows the checkout line.
|
|
204
|
+
|
|
205
|
+
The core needs only `httpx` and OpenTelemetry. Each extra installs the OpenInference
|
|
206
|
+
instrumentor for a framework (and, for `openai` and `langchain`, the client the SDK hands out):
|
|
207
|
+
|
|
208
|
+
| Extra | For |
|
|
209
|
+
|---|---|
|
|
210
|
+
| `[openai]` | the OpenAI client (`agent.openai()`), OpenAI tracing |
|
|
211
|
+
| `[langchain]` | LangChain and LangGraph tracing, `agent.langchain()` (langchain-openai) |
|
|
212
|
+
| `[anthropic]` | Anthropic SDK tracing |
|
|
213
|
+
| `[llama-index]` | LlamaIndex tracing |
|
|
214
|
+
| `[crewai]` | CrewAI tracing |
|
|
215
|
+
| `[openai-agents]` | OpenAI Agents SDK tracing (bridge to OpenTelemetry) |
|
|
216
|
+
| `[google-adk]` | Google ADK tracing |
|
|
217
|
+
| `[pydantic-ai]` | Pydantic AI (native OpenTelemetry, converted by OpenInference) |
|
|
218
|
+
| `[smolagents]`, `[dspy]`, `[litellm]`, `[bedrock]`, `[mistral]`, `[groq]`, `[autogen]`, `[agno]` | those libraries (the smolagents and AutoGen instrumentors need Python 3.10+: on 3.9 those two extras install nothing) |
|
|
219
|
+
| `[all]` | everything above |
|
|
220
|
+
|
|
221
|
+
Install the framework itself as usual (`pip install langgraph`, `pip install crewai`...): the
|
|
222
|
+
extras do not pin your framework versions.
|
|
223
|
+
|
|
224
|
+
## Quickstart (5 minutes)
|
|
225
|
+
|
|
226
|
+
**1. Get a key.** In the console, open Agents › Connections › Connect code (`/agents?tab=connect`)
|
|
227
|
+
and click **Create SDK key**: the key (valid 90 days) is filled into the environment block shown
|
|
228
|
+
there. (Settings › API tokens does the same: create a token with the **Agents SDK** scope.) This
|
|
229
|
+
scope only reaches what the package calls (traces, the model router, configs, workers, knowledge
|
|
230
|
+
search, memories and evaluations), so a leaked key cannot touch the rest of your account.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
export PAC_BASE_URL=http://localhost:8787 # your Graticor API (on a deployed server: the address Connect code shows)
|
|
234
|
+
export PAC_API_KEY=pac_... # the Agents SDK token
|
|
235
|
+
export PAC_ACCOUNT=org_... # only for an organization account
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**2. Write an agent.**
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
import pac_agents as pac
|
|
242
|
+
|
|
243
|
+
pac.init() # reads PAC_* from the environment
|
|
244
|
+
agent = pac.agent("support-bot") # registers the code agent "support-bot"
|
|
245
|
+
client = agent.openai() # an openai.OpenAI on the Graticor model router
|
|
246
|
+
|
|
247
|
+
@agent.entrypoint
|
|
248
|
+
def answer(message, *, history=None):
|
|
249
|
+
reply = client.chat.completions.create(
|
|
250
|
+
model=agent.llm().model, # "model:support-bot": the console picks the model
|
|
251
|
+
messages=[{"role": "system", "content": agent.instructions},
|
|
252
|
+
*(history or []), {"role": "user", "content": message}],
|
|
253
|
+
)
|
|
254
|
+
return reply.choices[0].message.content
|
|
255
|
+
|
|
256
|
+
print(answer("Hello!"))
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**3. Run it.** A new code agent uses the **Simulated** model, so the first run works before any
|
|
260
|
+
provider is connected. Open the agent in the console (`agent.console_url`): the trace is there,
|
|
261
|
+
with the LLM call, tokens and the prompt.
|
|
262
|
+
|
|
263
|
+
**4. Pick a real model.** In the console, open the agent › Build › Models, choose a model (a
|
|
264
|
+
Graticor deployment or a connected provider), and run again. The code did not change. (A Graticor
|
|
265
|
+
deployment made while the server runs dry runs answers through the simulator too.)
|
|
266
|
+
|
|
267
|
+
**5. Run it from Graticor.** Add `agent.serve()` (or run `pac-agents serve my_app.py:agent`) and chat
|
|
268
|
+
with your code in the Playground: the agent's Build tab opens it from Preview, and a connected
|
|
269
|
+
worker answers. (People who can only read the agent get a Playground tab instead.)
|
|
270
|
+
|
|
271
|
+
## How model assignment works
|
|
272
|
+
|
|
273
|
+
Your code never names a provider model. It sends OpenAI-compatible requests to the Graticor model
|
|
274
|
+
router (`{PAC_BASE_URL}/api/agents/llm/v1`) with a model id in the router grammar:
|
|
275
|
+
|
|
276
|
+
| `model` | Resolves to |
|
|
277
|
+
|---|---|
|
|
278
|
+
| `model:<agent>` | the agent's main model (`config.model`) |
|
|
279
|
+
| `model:<agent>/<slot>` | the model of a named slot (`config.models[slot]`), else the main model |
|
|
280
|
+
| `<connection>/<model>` | a model of one of your provider connections (e.g. `openai/gpt-4.1-mini`) |
|
|
281
|
+
| `sim` | the Simulated model (free, deterministic, calls tools) |
|
|
282
|
+
| `platform-claude` | Graticor's own Claude, when the operator turns it on |
|
|
283
|
+
|
|
284
|
+
The router takes your personal token (`PAC_API_KEY`). It is not the deployment gateway at `/v1`,
|
|
285
|
+
which takes endpoint keys (`pac_sk_…`).
|
|
286
|
+
|
|
287
|
+
`platform-claude` answers only when the server sets `PAC_AGENTS_PLATFORM_CLAUDE=1` and
|
|
288
|
+
`ANTHROPIC_API_KEY`, and the account is listed in `PAC_AGENTS_PLATFORM_CLAUDE_ACCOUNTS` (or the
|
|
289
|
+
server runs with dev auth) (`apps/api/src/agents/llm/models.ts`). The production example
|
|
290
|
+
(`deploy/prod/.env.example`) does not set it, so there you bring a provider key or use a Graticor
|
|
291
|
+
deployment. A deployment that is a dry run (the server without `PAC_DEPLOY_EXECUTE=1`) answers
|
|
292
|
+
through the simulator, like `sim`.
|
|
293
|
+
|
|
294
|
+
`agent.llm(slot)` returns the handle (`base_url`, `api_key`, `model`, `headers`), and the helpers
|
|
295
|
+
build ready clients from it:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
agent.openai(slot=None) # openai.OpenAI
|
|
299
|
+
agent.async_openai(slot=None) # openai.AsyncOpenAI
|
|
300
|
+
agent.langchain(slot=None, **kw) # langchain_openai.ChatOpenAI (works in LangGraph nodes)
|
|
301
|
+
agent.litellm(slot=None) # kwargs for litellm.completion(**kw) or crewai.LLM(**kw)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Slots** let one agent use several models: `agent.langchain("planner")` and
|
|
305
|
+
`agent.langchain("writer")` show up as two rows in the console (Build > Models), each with its own
|
|
306
|
+
model picker. A slot nobody assigned falls back to the main model; an agent with no model at all
|
|
307
|
+
answers `409 model_not_assigned` with a link to the console. Graticor keeps up to 20 slots per agent
|
|
308
|
+
(the first 20 your code declares; later ones still work and use the main model).
|
|
309
|
+
|
|
310
|
+
**Images.** The router takes text parts and, in user messages, `image_url` parts as PNG or JPEG
|
|
311
|
+
data URLs: at most 8 images per request, 1.5 MB each. It never fetches a link, so send the bytes,
|
|
312
|
+
not an `https://` URL (that answers `400 unsupported_content`). The assigned model must read images
|
|
313
|
+
(and its fallback, when it has one); otherwise the router answers `400 model_reads_no_images` with a
|
|
314
|
+
link to Build > Models, which says under the main model whether it takes images.
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
client = agent.openai()
|
|
318
|
+
client.chat.completions.create(model=agent.llm().model, messages=[{"role": "user", "content": [
|
|
319
|
+
{"type": "text", "text": "What is in this picture?"},
|
|
320
|
+
{"type": "image_url", "image_url": {"url": "data:image/png;base64,…"}},
|
|
321
|
+
]}])
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Draft and published.** The console edits a draft; Publish creates a numbered version.
|
|
325
|
+
`PAC_AGENT_VERSION` picks which one the code uses:
|
|
326
|
+
|
|
327
|
+
- unset and `PAC_ENV=dev` (the default): the **draft**, so console edits apply at once;
|
|
328
|
+
- unset and `PAC_ENV=staging`: the **staging** version (the published one while the agent has none);
|
|
329
|
+
- unset in any other environment (`PAC_ENV=prod`...): the **published** version (the draft while
|
|
330
|
+
the agent was never published);
|
|
331
|
+
- `draft`, `published`, `staging` or a version number: exactly that config.
|
|
332
|
+
|
|
333
|
+
A production server that forgets `PAC_ENV` reads the draft, so unpublished edits reach your users
|
|
334
|
+
at once. When neither `PAC_ENV` nor `PAC_AGENT_VERSION` is set and the agent has a published
|
|
335
|
+
version, `agent.config()` warns once per process (after a pull that worked):
|
|
336
|
+
|
|
337
|
+
```text
|
|
338
|
+
pac_agents: PAC_ENV is not set: this process reads the draft of support-bot; v3 is published. Set PAC_ENV=prod in production.
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Set `PAC_ENV=dev` on purpose on a dev machine and the warning stays off. Worker runs never warn:
|
|
342
|
+
they run the version Graticor assigned. The console shows the same thing: the Monitor tab of a
|
|
343
|
+
published code agent says "N traces in 24 h used the draft".
|
|
344
|
+
|
|
345
|
+
The clients of `agent.openai()`, `agent.async_openai()` and `agent.langchain()` send
|
|
346
|
+
`x-pac-agent-version` on every request with the version in use **at that moment**: inside a worker
|
|
347
|
+
run or an evaluation item of the agent, the run's version (the draft for playground runs, even in
|
|
348
|
+
a `PAC_ENV=prod` worker), else `PAC_AGENT_VERSION`'s. So a client made once at import follows each
|
|
349
|
+
run, and the run's config and its model calls agree. (`agent.litellm()` and `agent.llm().headers`
|
|
350
|
+
carry the value of the moment you call them, as does a client you build with your own
|
|
351
|
+
`http_client`.) The router serves the models of the version the request names: the draft's for `draft`, that
|
|
352
|
+
version's for a number, and the published version's otherwise (the draft's for a never-published
|
|
353
|
+
agent). Spans carry `pac.agent.version`
|
|
354
|
+
and `pac.config.hash`, so every trace says which config produced it, and experiments compare
|
|
355
|
+
drafts with published versions.
|
|
356
|
+
|
|
357
|
+
**Defaults from code.** `pac.agent(name, instructions=..., model="openai/gpt-4.1-mini",
|
|
358
|
+
models={"writer": "sim"})` seeds a *new* agent's draft. After that the console owns them.
|
|
359
|
+
|
|
360
|
+
## Tracing
|
|
361
|
+
|
|
362
|
+
`pac.init()` sets up OpenTelemetry:
|
|
363
|
+
|
|
364
|
+
- a `TracerProvider` with the resource `service.name`, `pac.agent.name`, `gen_ai.main_agent.name`,
|
|
365
|
+
`deployment.environment.name` and `pac.sdk.version` (an existing global provider is reused: our
|
|
366
|
+
exporter is added to it);
|
|
367
|
+
- a batch exporter sending protobuf OTLP/HTTP (gzip) to `{PAC_BASE_URL}/api/agents/otlp/v1/traces`;
|
|
368
|
+
- every installed OpenInference instrumentor (`instrument="auto"`), each guarded so a broken
|
|
369
|
+
package never breaks your app: OpenAI, Anthropic, LangChain/LangGraph, LlamaIndex, CrewAI,
|
|
370
|
+
OpenAI Agents, Google ADK, DSPy, smolagents, LiteLLM, Bedrock, Mistral, Groq, AutoGen, Agno and
|
|
371
|
+
Pydantic AI. Pass `instrument=["openai", "langchain"]` to pick, or `instrument=False`.
|
|
372
|
+
|
|
373
|
+
**Which spans reach Graticor.** Only agent traces: a trace is sent when one of its spans runs inside
|
|
374
|
+
an agent's code (an entrypoint, a worker run, an evaluation item) or a `pac.session()`, or is an
|
|
375
|
+
LLM, tool, agent or other GenAI span (Graticor, OpenTelemetry GenAI or OpenInference). The other traces
|
|
376
|
+
of your application (an HTTP health check, a database query with no agent involved) stay out of
|
|
377
|
+
Graticor and are not stamped with `pac.*` attributes. `pac.init(export_all_spans=True)` (or
|
|
378
|
+
`PAC_EXPORT_ALL_SPANS=1`) sends every span of the process.
|
|
379
|
+
|
|
380
|
+
**What Graticor accepts.** The server caps each account at `PAC_AGENTS_DAILY_SPANS` spans a day
|
|
381
|
+
(default 200,000); past it the export answers 429 until the next UTC midnight. It also rejects the
|
|
382
|
+
spans of an agent the key's person may not edit ("no edit access to agent <name>"), and caps one
|
|
383
|
+
request at 16 MB and 10,000 spans (`apps/api/src/agents/traces/otlp.ts`).
|
|
384
|
+
|
|
385
|
+
**Several agents in one process.** Each trace belongs to its outermost agent: when a supervisor's
|
|
386
|
+
entrypoint calls a researcher's, the whole trace is the supervisor's (every span's resource says
|
|
387
|
+
so, however the spans are batched), and the researcher's spans keep `pac.agent.name=researcher`
|
|
388
|
+
as a span attribute.
|
|
389
|
+
|
|
390
|
+
`pac.init()` may run more than once (the CLI inits, then your module calls `pac.init()` at
|
|
391
|
+
import): the TracerProvider stays the same, with the new settings' processors in place of the old.
|
|
392
|
+
|
|
393
|
+
**OpenAI Agents SDK.** With the `[openai-agents]` extra, `pac.init()` bridges the SDK's own
|
|
394
|
+
traces to Graticor; without it, only the model calls are traced, not the agent, handoff and tool spans.
|
|
395
|
+
The SDK also sends its traces to OpenAI with its own exporter. `disable_openai_tracing=True`
|
|
396
|
+
removes that exporter, with or without the extra, even when nothing goes to Graticor (no key, offline,
|
|
397
|
+
`instrument=False`); other trace processors of the SDK stay (`pac.instrument_openai_agents()`
|
|
398
|
+
does the same on demand). The default (`None`) removes it only when it has no OpenAI key to send
|
|
399
|
+
with (no `OPENAI_API_KEY`, none set on the SDK, or your Graticor key, which
|
|
400
|
+
`set_default_openai_client(agent.async_openai())` hands it): such an exporter could only log
|
|
401
|
+
"OPENAI_API_KEY is not set, skipping trace export". When `pac.init()` runs before the SDK is
|
|
402
|
+
imported, the SDK is not imported for this: the check runs at the next `agent.llm()` (or its
|
|
403
|
+
clients), `agent.register()`, entrypoint call or worker start, and after the CLI loads your module.
|
|
404
|
+
The default also removes an exporter it kept once it is handed your Graticor key
|
|
405
|
+
(`set_default_openai_client(agent.async_openai())` after `pac.init()`), at the same moments; pass
|
|
406
|
+
`use_for_tracing=False` to `set_default_openai_client()` to be sure OpenAI never gets that key.
|
|
407
|
+
`disable_openai_tracing=False` leaves the exporter alone.
|
|
408
|
+
|
|
409
|
+
**LangGraph and LangChain.** A `ChatOpenAI` call is recorded twice, by the LangChain and by the
|
|
410
|
+
OpenAI instrumentor; the OpenAI span nests under the `ChatOpenAI` span, so Graticor counts its tokens
|
|
411
|
+
and cost once. Spans inside a node carry `metadata.langgraph_node`, which Graticor maps to the node of
|
|
412
|
+
the registered graph.
|
|
413
|
+
|
|
414
|
+
**Manual spans.**
|
|
415
|
+
|
|
416
|
+
```python
|
|
417
|
+
@pac.trace # a "chain" span named after the function
|
|
418
|
+
def plan(question): ...
|
|
419
|
+
|
|
420
|
+
@pac.trace(name="research", kind="agent") # an "invoke_agent research" span
|
|
421
|
+
def research(topic): ...
|
|
422
|
+
|
|
423
|
+
@pac.tool # an "execute_tool lookup" span with arguments and result
|
|
424
|
+
def lookup(order_id: str) -> str: ...
|
|
425
|
+
|
|
426
|
+
with pac.span("rerank", kind="reranker", input=query) as s:
|
|
427
|
+
s.set_output(ranked)
|
|
428
|
+
s.set_attribute("rerank.model", "bge")
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Kinds: `agent`, `chain`, `tool`, `llm`, `retriever`, `embedding`, `reranker`, `guardrail`,
|
|
432
|
+
`evaluator`, `memory`, `handoff`, `http`, `other`. Node kinds (`agent`, `chain`, `tool`,
|
|
433
|
+
`retriever`, `memory`, `handoff`) set `graph.node.id`, so they become nodes of the observed graph.
|
|
434
|
+
Decorators work on sync and async functions and generators; exceptions are recorded and re-raised.
|
|
435
|
+
A traced generator's span covers the whole iteration and works when each step runs in another
|
|
436
|
+
context (Starlette's `StreamingResponse`, a thread pool); `send()`, `throw()` and `close()` reach
|
|
437
|
+
your generator. Recording arguments and results is best-effort: a value that cannot be read (an
|
|
438
|
+
unread streaming response, data nested thousands of levels deep) is recorded as its repr or a
|
|
439
|
+
placeholder, and never stops your function or loses its result.
|
|
440
|
+
`@agent.entrypoint` wraps its function in an `invoke_agent <agent>` span.
|
|
441
|
+
|
|
442
|
+
**Sessions and users.** Group the spans of a conversation and attribute them to an end user:
|
|
443
|
+
|
|
444
|
+
```python
|
|
445
|
+
with pac.session(thread_id, user_id="u-42", metadata={"plan": "pro"}, tags=["beta"]):
|
|
446
|
+
answer(message)
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**Logs and scores.** `pac.log("cache miss", level="warn")` adds an event to the current span (and
|
|
450
|
+
a log line in the playground during a worker run). `pac.score(trace_id, "user-thumbs", value=1.0)`
|
|
451
|
+
attaches a score to a trace; `pac.current_trace_id()` gives the id.
|
|
452
|
+
|
|
453
|
+
**Content capture.** By default prompts, outputs and tool arguments are recorded (Graticor hides them
|
|
454
|
+
from members without the `agents.write` permission). `pac.init(capture_content=False)` or
|
|
455
|
+
`PAC_CAPTURE_CONTENT=0` keeps them out of traces: spans then carry timings, tokens, cost, models
|
|
456
|
+
and errors only (error messages included). That covers the OpenInference instrumentors, Pydantic
|
|
457
|
+
AI's own instrumentation (`include_content=False`; a Pydantic AI too old for it is not
|
|
458
|
+
instrumented) and `pac.log()` lines, whose span events then keep only their level (the playground
|
|
459
|
+
still shows the line during a worker run). The agent's console setting "Trace content: Metadata
|
|
460
|
+
only" strips them on the server side too (agent › Settings › Data & advanced › Trace content).
|
|
461
|
+
Authorization headers, cookies, API keys and tokens are always dropped.
|
|
462
|
+
|
|
463
|
+
**Flushing.** Spans are batched; `pac.flush()` sends them now, and they are flushed at exit.
|
|
464
|
+
`pac.shutdown()` flushes, uninstruments and closes the client.
|
|
465
|
+
|
|
466
|
+
## Registering the architecture
|
|
467
|
+
|
|
468
|
+
`agent.register(obj)` reads the structure of a framework object and sends it to Graticor, which draws
|
|
469
|
+
it in the agent's Build › Graph and on Monitor › Charts (declared graph) next to the graph rebuilt
|
|
470
|
+
from traces (observed graph).
|
|
471
|
+
Node ids are the names spans carry (LangGraph node names, CrewAI roles, agent and tool names), so
|
|
472
|
+
a trace can light up its path. `pac-agents graph module:attr` prints the graph without sending
|
|
473
|
+
anything: it imports your module with `PAC_OFFLINE=1`, so the module's own `pac.init()`,
|
|
474
|
+
`pac.agent()` and `agent.register()` make no request (`--push` registers it).
|
|
475
|
+
|
|
476
|
+
```python
|
|
477
|
+
graph = builder.compile()
|
|
478
|
+
agent.register(graph)
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
| Framework | Pass | What becomes the graph |
|
|
482
|
+
|---|---|---|
|
|
483
|
+
| LangGraph | a compiled graph (or the `StateGraph` builder) | `start`/`end`, each node (id = node name), conditional edges with their route key, `ToolNode` tools as tool nodes, subgraphs (children carry `parent`), chat models used as nodes as `llm` nodes |
|
|
484
|
+
| CrewAI | a `Crew` (or one `Agent`) | tasks in order (start > task 1 > ... > end), each task's agent (id = role) with its model and slot, task context as data edges, tools, a manager for hierarchical crews, delegation, memory and knowledge |
|
|
485
|
+
| OpenAI Agents SDK | the entry `Agent` | every agent reachable through handoffs (cycles are fine), models and slots, function, hosted and MCP tools, agents used as tools |
|
|
486
|
+
| LlamaIndex | a `Workflow`, an `AgentWorkflow` or a workflow agent | steps linked by the events they emit and accept (labelled), StartEvent/StopEvent as start/end, human-in-the-loop events; agent workflows as agents with tools and handoffs |
|
|
487
|
+
| Google ADK | the root agent | the agent tree: LLM agents with models, Sequential/Parallel/Loop agents as subgraphs with their control flow, transfers, tools, `AgentTool`s |
|
|
488
|
+
| Pydantic AI | an `Agent` | the agent, its model, function tools and toolsets (MCP servers) |
|
|
489
|
+
| smolagents | a `CodeAgent` / `ToolCallingAgent` | the agent, its model, tools and managed agents |
|
|
490
|
+
| anything else | a dict | an AgentGraph you write yourself (validated) |
|
|
491
|
+
|
|
492
|
+
A hand-written graph:
|
|
493
|
+
|
|
494
|
+
```python
|
|
495
|
+
agent.register({
|
|
496
|
+
"schema": "pac.agent_graph/v1",
|
|
497
|
+
"framework": "custom",
|
|
498
|
+
"nodes": [
|
|
499
|
+
{"id": "router", "kind": "router", "name": "Router", "slot": "router"},
|
|
500
|
+
{"id": "search", "kind": "tool", "name": "search"},
|
|
501
|
+
{"id": "answer", "kind": "agent", "name": "Answer"},
|
|
502
|
+
],
|
|
503
|
+
"edges": [
|
|
504
|
+
{"source": "router", "target": "search", "kind": "tool"},
|
|
505
|
+
{"source": "router", "target": "answer", "kind": "conditional", "label": "has context"},
|
|
506
|
+
],
|
|
507
|
+
})
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
Node kinds: `agent`, `llm`, `tool`, `retriever`, `knowledge`, `memory`, `router`, `subgraph`,
|
|
511
|
+
`chain`, `start`, `end`, `other`. Edge kinds: `control`, `conditional`, `handoff`, `delegation`,
|
|
512
|
+
`data`, `tool`. Graphs are capped at 500 nodes and 2000 edges.
|
|
513
|
+
|
|
514
|
+
The adapters only read attributes (no framework is imported to detect one). When one cannot read
|
|
515
|
+
an object, it logs a warning and registers no graph: the observed graph still shows what runs.
|
|
516
|
+
`from pac_agents.architecture import build_graph` gives the same dict without registering.
|
|
517
|
+
`agent.serve(obj)` and `pac-agents serve` register the object they serve.
|
|
518
|
+
|
|
519
|
+
## Serving: the worker
|
|
520
|
+
|
|
521
|
+
A code agent runs where your code runs. To let Graticor trigger it (playground, schedules, webhooks,
|
|
522
|
+
evaluations started from the console), run a worker:
|
|
523
|
+
|
|
524
|
+
```python
|
|
525
|
+
agent.serve() # the @agent.entrypoint function
|
|
526
|
+
agent.serve(graph) # or a LangGraph graph, a CrewAI crew, an OpenAI Agents agent, a callable
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
```bash
|
|
530
|
+
pac-agents serve my_app:agent # an Agent with an entrypoint (module path)
|
|
531
|
+
pac-agents serve my_app.py:run # its @agent.entrypoint function: the same worker
|
|
532
|
+
pac-agents serve my_app.py:graph # a framework object in a file, served as the agent that owns it
|
|
533
|
+
pac-agents serve my_app:crew --name research-crew --concurrency 4
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
An object that is not an `Agent` is served (and evaluated, and pushed by `graph --push`) as the
|
|
537
|
+
agent named, in order: `--name`; the agent that owns it, that is the one whose
|
|
538
|
+
`@agent.entrypoint` it is (which then runs as usual), that serves it, or that was given it by
|
|
539
|
+
`agent.register(obj)`; the module's only `Agent`; `PAC_AGENT_NAME`; the object's own `name` (unless
|
|
540
|
+
a framework default such as `agent`); the module's name. An object several agents registered
|
|
541
|
+
needs `--name` (or `PAC_AGENT_NAME` naming one of them), else the command exits with code 2.
|
|
542
|
+
|
|
543
|
+
The worker long-polls Graticor, runs each job in a thread (2 at a time by default), streams tool calls
|
|
544
|
+
and logs to the playground, and posts the answer with tools used and token counts. Its spans land
|
|
545
|
+
in the trace Graticor opened for the run. Ctrl+C stops polling and lets running jobs finish (twice
|
|
546
|
+
quits at once). While Graticor is down it backs off and reconnects.
|
|
547
|
+
|
|
548
|
+
How each target is called:
|
|
549
|
+
|
|
550
|
+
| Target | Call |
|
|
551
|
+
|---|---|
|
|
552
|
+
| entrypoint / callable | `fn(message, history=..., variables=..., end_user=..., thread_id=..., run_id=...)`, passing only the keyword arguments it declares; async functions are awaited on the SDK's event loop |
|
|
553
|
+
| LangGraph | `graph.invoke({"messages": history + [user]}, config={"configurable": {"thread_id": ...}})`, or `ainvoke` on the SDK's event loop when a node (or a subgraph's node) is async only; the answer is the last AI message (with a checkpointer, only the new message is sent) |
|
|
554
|
+
| CrewAI | `crew.kickoff(inputs={"message": ..., **variables})`; the answer is the crew's raw output |
|
|
555
|
+
| OpenAI Agents | `Runner.run(agent, message or history + [user])` on the SDK's event loop; the answer is `final_output` |
|
|
556
|
+
|
|
557
|
+
Async code runs on one event loop the SDK keeps for the whole process (with the job's context),
|
|
558
|
+
so async clients created once at import keep working from one run to the next. The clients of
|
|
559
|
+
`agent.async_openai()` and `agent.langchain()` also work from any event loop (one connection pool
|
|
560
|
+
per loop), for code that calls `asyncio.run()` or `Runner.run_sync()` itself.
|
|
561
|
+
|
|
562
|
+
The entrypoint returns a `str` (the answer) or a `dict`/`list` (JSON output); an exception fails
|
|
563
|
+
the run with its message. JSON output is converted to plain JSON (dates as ISO text, pydantic
|
|
564
|
+
models and dataclasses as objects, LangChain messages as `{"type", "content"}`, NaN as null). What
|
|
565
|
+
the worker sends fits Graticor's limits: the text output is cut at 200 000 characters, the JSON output
|
|
566
|
+
is left out when the result would pass about 900 KB (the text says the same), and at most 200 tool
|
|
567
|
+
names are listed. Should Graticor refuse the result anyway, or the worker fail while reporting it, the
|
|
568
|
+
run is still completed (with the text only, or with the error), so it never waits for its timeout.
|
|
569
|
+
A run queued while no worker is connected fails after 60 seconds with
|
|
570
|
+
"No worker is connected for <agent>"; the Playground and Build > Code show whether a worker is
|
|
571
|
+
connected. Inside a run, `agent.config()`, `agent.instructions`, `agent.param()`, `agent.version`
|
|
572
|
+
and `agent.config_hash` are those of the config Graticor assigned to that run (the draft for playground
|
|
573
|
+
runs, else the version the run asked for). A run cancelled in the console stops being reported;
|
|
574
|
+
your code is not interrupted.
|
|
575
|
+
|
|
576
|
+
## Params
|
|
577
|
+
|
|
578
|
+
Typed values your code reads and the console edits (Build > Params), without a deploy:
|
|
579
|
+
|
|
580
|
+
```python
|
|
581
|
+
temperature = agent.param("temperature", 0.2, description="Sampling temperature.")
|
|
582
|
+
tone = agent.param("tone", "friendly")
|
|
583
|
+
strict = agent.param("strict_mode", False)
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
The type is `string`, `number`, `boolean` or `text` (from the default, or `type=`). The console
|
|
587
|
+
value is converted to it; a bad value falls back to the default with a warning. Params are
|
|
588
|
+
declared at registration, so call `agent.param` at import time for them to show up before the
|
|
589
|
+
first run.
|
|
590
|
+
|
|
591
|
+
Names are identifiers: letters, digits and `_`, starting with a letter or `_` (64 at most;
|
|
592
|
+
`ValueError` otherwise). Graticor shows up to 64 params per agent (the first declared); a default
|
|
593
|
+
longer than 8 000 characters stays in your code (the console shows no default for it) and a
|
|
594
|
+
description is cut at 500 characters, so one oversized declaration never makes Graticor refuse the
|
|
595
|
+
registration.
|
|
596
|
+
|
|
597
|
+
## Knowledge bases
|
|
598
|
+
|
|
599
|
+
```python
|
|
600
|
+
kb = pac.knowledge("handbook") # a name or an id ("kb_8Qx...")
|
|
601
|
+
hits = kb.search("vacation policy", top_k=5)
|
|
602
|
+
for h in hits:
|
|
603
|
+
print(h["citation"], h["score"], h["text"][:80])
|
|
604
|
+
|
|
605
|
+
kb.add_text("FAQ", "Refunds take 5 days.")
|
|
606
|
+
kb.add_file("handbook.pdf") # md, txt, html, csv, json, pdf (≤ 20 MB)
|
|
607
|
+
kb.add_url("https://example.com/docs")
|
|
608
|
+
retriever = kb.as_langchain_retriever(top_k=4)
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
Search is Graticor's hybrid search (BM25 and vectors, fused) with citations ("[1] Title › Heading").
|
|
612
|
+
A query is cut at 4 000 characters and `top_k` kept between 1 and 50, Graticor's limits.
|
|
613
|
+
Each call is a `retrieval <kb>` span with the returned documents, which feeds the groundedness
|
|
614
|
+
evaluator. Indexing runs in the background after `add_*` (the document comes back `pending`).
|
|
615
|
+
Adding content the knowledge base already has raises `pac.PacApiError` with
|
|
616
|
+
`code == "duplicate_document"`; `e.body["documentId"]` is the document that has it, so a seeding
|
|
617
|
+
script can carry on.
|
|
618
|
+
|
|
619
|
+
A setup script can create the knowledge base it seeds:
|
|
620
|
+
|
|
621
|
+
```python
|
|
622
|
+
kb = pac.knowledge("handbook", create=True, description="Policies")
|
|
623
|
+
print("created" if kb.created else "already there", kb.id)
|
|
624
|
+
kb.add_text("Refunds", "Refunds take 5 days.")
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
With `create=True` the name is looked up at once, and the base is created when no base has
|
|
628
|
+
that name (`kb.created` is then `True`); running the script again reuses it. Creating needs a
|
|
629
|
+
personal token with full scope (`PAC_API_KEY` from Settings > API tokens): an Agents SDK key can
|
|
630
|
+
search and add documents only, and gets a `pac.PacError` that says so. `create=True` takes a
|
|
631
|
+
name, not an id. Without it, `pac.knowledge()` sends nothing until first use. The console's
|
|
632
|
+
New knowledge base (Agents › Library › Knowledge, `/knowledge`) does the same by hand.
|
|
633
|
+
|
|
634
|
+
## Memory
|
|
635
|
+
|
|
636
|
+
Long-term memory per end user, or shared by the agent:
|
|
637
|
+
|
|
638
|
+
```python
|
|
639
|
+
mem = agent.memory(user="u-42") # scope "user"; agent.memory() is scope "agent"
|
|
640
|
+
mem.add("Prefers short answers", kind="preference") # fact | preference | episode | instruction
|
|
641
|
+
for m in mem.search("how should I answer?", limit=3):
|
|
642
|
+
print(m["content"], m["score"])
|
|
643
|
+
mem.list()
|
|
644
|
+
mem.forget(memory_id) # one memory
|
|
645
|
+
mem.forget() # everything about u-42 (audited hard delete)
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
Calls are `create_memory` / `search_memory` / `delete_memory` spans. Treat recalled memories as
|
|
649
|
+
data in your prompts, not instructions.
|
|
650
|
+
|
|
651
|
+
## Guardrail checks
|
|
652
|
+
|
|
653
|
+
Graticor does not run your agent's loop, so your code asks it to check what the loop is about to read
|
|
654
|
+
or send. The check runs the company floor, the agent's policy (or the one you name) and its own
|
|
655
|
+
checks on Graticor (`POST /api/agents/:id/guardrails/check`). Policies live under Agents › Library ›
|
|
656
|
+
Guardrails (`/agents?tab=guardrails`); the agent's Monitor › Guardrails shows the call to make:
|
|
657
|
+
|
|
658
|
+
```python
|
|
659
|
+
result = agent.check(user_text, stage="input") # or stage="output" (prompt=the user message)
|
|
660
|
+
if result.blocked:
|
|
661
|
+
return result.message # what the user should see
|
|
662
|
+
user_text = result.text # masked when a check masked it
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
- **Monitor first**: the agent's checks only report what they would do (`result.would`) until you
|
|
666
|
+
pass `enforce=True`. Checks of the company floor keep the floor's mode.
|
|
667
|
+
- `policy="Support strict"` (a policy name or id) applies that policy in place of the agent's;
|
|
668
|
+
the floor still applies.
|
|
669
|
+
- `result.decision` is `"allow"`, `"mask"` or `"block"`. Each call is a `guardrail <stage>` span
|
|
670
|
+
with Graticor's verdicts; Graticor keeps the verdicts (never the text), so Monitor › Guardrails counts them.
|
|
671
|
+
- Graticor down (or no `PAC_API_KEY`, or a page that is not Graticor's at `PAC_BASE_URL`): with `enforce=False` the text is allowed with one warning
|
|
672
|
+
(`result.error` says why); with `enforce=True` the error is raised. A refusal (unknown policy,
|
|
673
|
+
no access) is always raised.
|
|
674
|
+
|
|
675
|
+
## Evaluations and CI gates
|
|
676
|
+
|
|
677
|
+
Run your agent locally over a Graticor dataset; Graticor scores the outputs and keeps the experiment next to
|
|
678
|
+
the ones started from the console:
|
|
679
|
+
|
|
680
|
+
```python
|
|
681
|
+
report = pac.evaluate(
|
|
682
|
+
agent,
|
|
683
|
+
dataset="faq-smoke", # id or name (Evaluations > Datasets)
|
|
684
|
+
evaluators=["builtin:exact-match", "builtin:latency-under-10s"],
|
|
685
|
+
repetitions=1,
|
|
686
|
+
gate={"builtin:exact-match": 0.8}, # mean score thresholds
|
|
687
|
+
) # raises pac.GateFailed when a gate is missed
|
|
688
|
+
print(report.summary()) # the experiment is in Evaluations > Experiments
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
`task=` evaluates another function or framework object than the entrypoint. With no `evaluators`
|
|
692
|
+
(and no `--evaluator` or `--gate` on the command line) the evaluator is `builtin:correctness`.
|
|
693
|
+
Built-in evaluators (`apps/api/src/agents/evals/evaluators.ts`): `builtin:correctness`,
|
|
694
|
+
`builtin:helpfulness`, `builtin:groundedness` (LLM judges, which need a judge model such as a
|
|
695
|
+
provider connection), `builtin:exact-match`, `builtin:contains-expected`, `builtin:valid-json`,
|
|
696
|
+
`builtin:tools-used`, `builtin:retrieved-documents`, `builtin:latency-under-10s`,
|
|
697
|
+
`builtin:cost-under-1c`, plus your own evaluators by id (Evaluations › Evaluators).
|
|
698
|
+
`builtin:cost-under-1c` scores only results that carry a cost. `builtin:goal-achieved` and
|
|
699
|
+
`builtin:user-experience` judge simulated users, so they score only platform runs
|
|
700
|
+
([Gate on a platform experiment](#gate-on-a-platform-experiment)). LLM judges count against the
|
|
701
|
+
account's daily judge budget on the server (`PAC_AGENTS_JUDGE_DAILY_USD`, default $1).
|
|
702
|
+
|
|
703
|
+
From the command line (exit code 1 when a gate fails):
|
|
704
|
+
|
|
705
|
+
```bash
|
|
706
|
+
pac-agents eval my_app.py:agent --dataset faq-smoke \
|
|
707
|
+
--evaluator builtin:latency-under-10s --gate builtin:exact-match=0.8
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
A `--gate` evaluator is added to the evaluators when it is not listed.
|
|
711
|
+
|
|
712
|
+
A GitHub Actions job:
|
|
713
|
+
|
|
714
|
+
```yaml
|
|
715
|
+
- run: pip install "graticor[openai]"
|
|
716
|
+
- run: pac-agents eval my_app:agent --dataset faq-smoke --evaluator builtin:correctness --gate builtin:correctness=0.8
|
|
717
|
+
env:
|
|
718
|
+
PAC_BASE_URL: https://graticor.example.com
|
|
719
|
+
PAC_API_KEY: ${{ secrets.PAC_API_KEY }}
|
|
720
|
+
PAC_ENV: ci
|
|
721
|
+
PAC_AGENT_VERSION: draft # evaluate the draft before publishing it
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
Datasets with **simulated users** (scenario items: Graticor plays a persona over several turns) run on the
|
|
725
|
+
platform only: `pac.evaluate` and `pac-agents eval module:attr` refuse them before anything is posted
|
|
726
|
+
("This dataset has 2 simulated users: Graticor plays those conversations itself, so run it on the
|
|
727
|
+
platform: pac-agents eval --on-pac AGENT --dataset ...").
|
|
728
|
+
|
|
729
|
+
### Gate on a platform experiment
|
|
730
|
+
|
|
731
|
+
`--on-pac AGENT` lets Graticor run the experiment itself (the same as the agent's Evaluate tab): it works
|
|
732
|
+
for hosted and workflow agents, agents kept in git as config, Python code agents with a worker
|
|
733
|
+
running, and datasets with simulated users. A TypeScript code agent cannot run there yet: there is no
|
|
734
|
+
TypeScript worker, so Graticor cannot start it (`apps/api/src/agents/runtime/run.ts`
|
|
735
|
+
`noWorkerMessage`). The command waits, prints the summary, and exits 1 when a gate is missed, 3 when
|
|
736
|
+
the experiment is still running at `--timeout` (default 1800 s; it goes on in Graticor):
|
|
737
|
+
|
|
738
|
+
```yaml
|
|
739
|
+
- run: pip install graticor
|
|
740
|
+
- run: pac-agents eval --on-pac support-bot --dataset faq-smoke --gate builtin:correctness=0.8
|
|
741
|
+
env:
|
|
742
|
+
PAC_BASE_URL: https://graticor.example.com
|
|
743
|
+
PAC_API_KEY: ${{ secrets.PAC_API_KEY }} # an Agents SDK key or a full-scope token
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
`--version draft` (the default), `published`, `staging` or a number picks the version Graticor runs.
|
|
747
|
+
Progress goes to stderr (`Running: 3 of 12`), the summary to stdout. A code agent needs its worker
|
|
748
|
+
running (`pac-agents serve`) while Graticor runs it. From Python: `pac.evaluate_on_pac("support-bot",
|
|
749
|
+
"faq-smoke", gate={"builtin:correctness": 0.8})` returns the same `Report` (raises
|
|
750
|
+
`pac.GateFailed`, or `pac.EvaluationTimeout` past `timeout_s`).
|
|
751
|
+
|
|
752
|
+
## Config as code
|
|
753
|
+
|
|
754
|
+
Hosted and workflow agents can live in your repository as code. `pac.define` writes the same
|
|
755
|
+
`pac.agent/v1` file as the console's **Export** and the code view's JSON tab; pushing it creates the
|
|
756
|
+
agent, or replaces the draft of the agent with that name (published versions do not change until
|
|
757
|
+
you publish).
|
|
758
|
+
|
|
759
|
+
```python
|
|
760
|
+
# support-bot.agent.py
|
|
761
|
+
import pac_agents as pac
|
|
762
|
+
from pac_agents import models, ref
|
|
763
|
+
|
|
764
|
+
support_bot = pac.define(
|
|
765
|
+
"support-bot",
|
|
766
|
+
kind="hosted", # or "workflow"
|
|
767
|
+
description="Answers billing questions for customers.",
|
|
768
|
+
tags=["support"],
|
|
769
|
+
instructions="""\
|
|
770
|
+
# Role
|
|
771
|
+
You answer billing questions. Never promise refunds.
|
|
772
|
+
""",
|
|
773
|
+
model={"ref": models.provider("openai", "gpt-5-mini"), "params": {"temperature": 0.2}},
|
|
774
|
+
tools=[
|
|
775
|
+
{"type": "builtin", "name": "knowledge_search"},
|
|
776
|
+
{"type": "agent", "agentId": ref.agent("billing-expert")},
|
|
777
|
+
],
|
|
778
|
+
knowledge=[{"kbId": ref.knowledge_base("help-center"), "mode": "auto", "topK": 5}],
|
|
779
|
+
history_messages=20,
|
|
780
|
+
secrets=[{"name": "ZENDESK_TOKEN", "hosts": ["api.zendesk.com"]}],
|
|
781
|
+
)
|
|
782
|
+
|
|
783
|
+
if __name__ == "__main__":
|
|
784
|
+
pac.init()
|
|
785
|
+
print(support_bot.push()) # Created support-bot (agt_...): draft 3f2a9c1.
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
```bash
|
|
789
|
+
pac-agents push support-bot.agent.py # the same, from the command line or CI
|
|
790
|
+
pac-agents pull support-bot --format python # the console's agent as this code (support-bot.agent.py)
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
- **Keywords** are the agent config's top-level keys in snake_case (`history_messages` ->
|
|
794
|
+
`historyMessages`); **nested values are written as in the `.agent.json` file** (camelCase JSON:
|
|
795
|
+
`{"topK": 5}`). `description` and `tags` are the agent's; `config_description=` sets the config's
|
|
796
|
+
own description when it differs. Keys this SDK does not know yet pass through (Graticor lists what it
|
|
797
|
+
leaves out). Values must be JSON data or refs: anything else (a set, an object, NaN) raises
|
|
798
|
+
`PacConfigError` naming the field.
|
|
799
|
+
- **Ids never travel.** Name what the agent uses and Graticor resolves each name in the account you
|
|
800
|
+
push to: `ref.agent`, `ref.knowledge_base`, `ref.deployment`, `ref.connection`, `ref.environment`,
|
|
801
|
+
`ref.policy` (guardrail policy), `ref.skill`, `ref.connector` (a connected app); models with
|
|
802
|
+
`models.provider(connection, model)`, `models.deployment(name)`, `models.sim()`,
|
|
803
|
+
`models.platform_claude()`. A name that is not in the account fails the push with that account's
|
|
804
|
+
closest names (`pac.UnresolvedRefs`, exit 1 on the command line); `drop_unresolved=True`
|
|
805
|
+
(`--drop-unresolved`) leaves those places empty instead (an attached knowledge base is left out,
|
|
806
|
+
a model becomes "not set"; readiness reminds you).
|
|
807
|
+
- **Secrets** are listed by name with their hosts, never with a value; add missing ones under
|
|
808
|
+
Agents › Connections › Secrets (publishing waits for them, as in the console). Pinned step outputs (debug data)
|
|
809
|
+
and MCP tool pins are never part of a file: Graticor lists and pins each server's tools again on save.
|
|
810
|
+
- **Workflow agents** load their steps from the pulled workflow file:
|
|
811
|
+
`pac.define("ticket-triage", kind="workflow", workflow=pac.load_workflow("ticket-triage.workflow.json"), ...)`.
|
|
812
|
+
- `definition.preview()` (`--dry-run`) answers what a push would do without storing anything: the
|
|
813
|
+
names found and missing, the secrets, the hosts the agent may send data to, what is left out, the
|
|
814
|
+
problems that would refuse it, the workflow checklist and the changes against the current draft.
|
|
815
|
+
- `definition.push(publish="note")` (`--publish NOTE`) publishes the draft afterwards: readiness
|
|
816
|
+
blockers and the workflow check refuse it as in the console (exit 1), nothing new to publish is
|
|
817
|
+
not an error.
|
|
818
|
+
- **Staging.** `push(publish="note", stage="staging")` (`--publish NOTE --stage staging`, also on
|
|
819
|
+
`workflow push`) publishes to Staging and prints "Published support-bot v4 to Staging. Promote it
|
|
820
|
+
to production: pac-agents promote support-bot". An agent with "Require staging before production"
|
|
821
|
+
refuses a production publish (exit 1) with Graticor's sentence and "Publish to Staging with --publish
|
|
822
|
+
--stage staging, then run pac-agents promote support-bot." `pac-agents promote AGENT [--version N]
|
|
823
|
+
[--note NOTE]` (`pac_agents.define.promote_agent`) moves the staging version, or version N, to
|
|
824
|
+
production at once ("Promoted support-bot v4 to production."; nothing to promote is exit 0). It
|
|
825
|
+
needs a personal token with full scope; a gradual promotion (a canary) is the console's (the
|
|
826
|
+
agent's Settings › Notifications & releases; the CLI's own messages call it "Settings › Releases").
|
|
827
|
+
- **The base of a Python file.** `pac-agents pull --format python` and the code view write the draft
|
|
828
|
+
the file was made from: `pac.define(..., base="3f2a9c1d...")`, with a comment line that says so
|
|
829
|
+
(no `base` while the console has unsaved edits). `pac-agents push x.agent.py` and `.push()` send it
|
|
830
|
+
as the draft check: when someone changed the draft in the console since, the push is refused
|
|
831
|
+
(exit 1) with "The draft of support-bot changed since this file was made. Pull it again
|
|
832
|
+
(pac-agents pull support-bot --format python), or push with --force to replace the draft."
|
|
833
|
+
`--force` (`push(force=True)`) sends no check; `--dry-run` and `--name` for another agent send
|
|
834
|
+
none either. After a CLI push the file's `base="…"` is the new draft's hash, so the next push
|
|
835
|
+
works (when the literal is not in the file, a Note says to pull again or use `--force`); after
|
|
836
|
+
`.push()` the definition's `.base` is.
|
|
837
|
+
- **Keys.** Pushing and publishing write drafts: they need a **config token** (Settings > API
|
|
838
|
+
tokens, access **Agent configs**: pull, push, workflow push, readiness and publish, nothing else,
|
|
839
|
+
so CI never holds a key that can do everything) or a personal token with full scope. An Agents
|
|
840
|
+
SDK key reads configs, files and workflows and answers 403 `token_scope` on a push ("Pushing
|
|
841
|
+
changes needs a config token or a personal token with full scope.").
|
|
842
|
+
- **Who runs it and who may use it** are owner settings in the console (Settings > Access): a file
|
|
843
|
+
never sets them, and a push into an existing agent that carries them is refused.
|
|
844
|
+
|
|
845
|
+
`pac-agents pull AGENT` writes `AGENT.agent.json` byte for byte as the console's Export downloads it
|
|
846
|
+
(`--version published` or a number for another version, `-o -` to print it). `pac-agents push
|
|
847
|
+
FILE.json` sends the file back; when the file was pulled from the agent it replaces, the push
|
|
848
|
+
refuses (exit 1) if someone changed the draft since, so console edits are never overwritten
|
|
849
|
+
silently: pull again, or push with `--force`.
|
|
850
|
+
|
|
851
|
+
### A CI recipe
|
|
852
|
+
|
|
853
|
+
Keep the agent files in `agents/` and add `.github/workflows/pac-agents.yml` (the code view's "How
|
|
854
|
+
to use it" shows this file for your agent, with your address and install line):
|
|
855
|
+
|
|
856
|
+
```yaml
|
|
857
|
+
name: Graticor agents
|
|
858
|
+
on:
|
|
859
|
+
pull_request:
|
|
860
|
+
paths: ["agents/**"]
|
|
861
|
+
push:
|
|
862
|
+
branches: [main]
|
|
863
|
+
paths: ["agents/**"]
|
|
864
|
+
jobs:
|
|
865
|
+
agents:
|
|
866
|
+
runs-on: ubuntu-latest
|
|
867
|
+
env:
|
|
868
|
+
PAC_BASE_URL: "https://graticor.example.com"
|
|
869
|
+
PAC_ACCOUNT: "<account id>"
|
|
870
|
+
# A config token (Agent configs) or a personal token with full scope: pushing and publishing need one. Add it as a repository secret.
|
|
871
|
+
PAC_API_KEY: ${{ secrets.PAC_API_KEY }}
|
|
872
|
+
steps:
|
|
873
|
+
- uses: actions/checkout@v4
|
|
874
|
+
- uses: actions/setup-python@v5
|
|
875
|
+
with:
|
|
876
|
+
python-version: "3.12"
|
|
877
|
+
- name: Install the Graticor SDK
|
|
878
|
+
run: |
|
|
879
|
+
pip install graticor
|
|
880
|
+
- name: Check
|
|
881
|
+
if: github.event_name == 'pull_request'
|
|
882
|
+
run: |
|
|
883
|
+
pac-agents push agents/support-bot.agent.json --dry-run
|
|
884
|
+
- name: Publish
|
|
885
|
+
if: github.event_name == 'push'
|
|
886
|
+
# the repository is the source of truth: --force replaces console edits to the draft (the pull request's dry run lists every change)
|
|
887
|
+
run: |
|
|
888
|
+
pac-agents push agents/support-bot.agent.json --force --publish "${{ github.sha }}"
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
Three choices:
|
|
892
|
+
|
|
893
|
+
- **Pull requests check, nothing changes.** `push --dry-run` lists the names found and missing, the
|
|
894
|
+
secrets, the hosts and every change against the draft (exit 1 when the push would be refused). For
|
|
895
|
+
a workflow agent kept as Python, check its steps too: `pac-agents workflow validate ticket-triage
|
|
896
|
+
agents/ticket-triage.workflow.json` before the dry run.
|
|
897
|
+
- **A merge pushes with `--force`.** The repository is the source of truth: the base in a committed
|
|
898
|
+
file is stale after the first push, and the pull request's dry run already showed what the push
|
|
899
|
+
replaces. Without `--force`, a console edit since the last pull stops the job (exit 1).
|
|
900
|
+
- **Staging first.** For an agent with staging, add `--stage staging` to the publish line, then
|
|
901
|
+
promote it: `pac-agents promote support-bot` (or the agent's Settings › Notifications & releases).
|
|
902
|
+
|
|
903
|
+
## Workflow files
|
|
904
|
+
|
|
905
|
+
A workflow agent's steps can be edited as a file next to your code:
|
|
906
|
+
|
|
907
|
+
```bash
|
|
908
|
+
pac-agents workflow pull ticket-triage # ticket-triage.workflow.json
|
|
909
|
+
pac-agents workflow diff ticket-triage ticket-triage.workflow.json # what a push would change
|
|
910
|
+
pac-agents workflow validate ticket-triage ticket-triage.workflow.json # the checklist (exit 1 on errors)
|
|
911
|
+
pac-agents workflow push ticket-triage ticket-triage.workflow.json # replace the draft's steps
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
- The file (`pac.workflow-file/v1`) is what the console's code view shows (Build › Code, the
|
|
915
|
+
`<name>.workflow.json` tab) and what its Download saves: `$pac` (the agent, its id, the version
|
|
916
|
+
pulled and `baseHash`), the steps, connections, groups and state, and the run's input
|
|
917
|
+
`variables`. The console's JSON view shows the spec only; its "Load a file…" reads this file too.
|
|
918
|
+
A pull writes it byte for byte as the console does.
|
|
919
|
+
- `push` replaces the draft's steps and variables only (everything else of the draft stays) and
|
|
920
|
+
sends `baseHash`: when the draft's workflow changed since your pull it stops with exit 1, "The
|
|
921
|
+
draft of ticket-triage changed since you pulled it (14:02 UTC). See the changes with pac-agents
|
|
922
|
+
workflow diff ticket-triage FILE, then pull again or push with --force." Once saved, the new base
|
|
923
|
+
is written into the file, so the next push works. Validation errors never block saving a draft;
|
|
924
|
+
the checklist is printed by step name (runs and publishing wait for the errors).
|
|
925
|
+
- Pinned step outputs are debug data: `pull --with-pins` keeps them (people who may edit only), and
|
|
926
|
+
a push keeps the draft's pins unless `--keep-pins` sends the file's.
|
|
927
|
+
- `diff` lists steps added, removed, changed (field by field, text line by line) or moved,
|
|
928
|
+
connections, groups, state and variables (exit 0 when there is nothing, 1 when they differ).
|
|
929
|
+
- From Python: `pac_agents.workflows.pull_workflow`, `push_workflow` (raises `pac.WorkflowConflict`),
|
|
930
|
+
`diff_workflows`, `validate_workflow`, and `pac.load_workflow(path)` (`.spec`, `.variables`,
|
|
931
|
+
`.base_hash`).
|
|
932
|
+
|
|
933
|
+
## Runs and outcomes
|
|
934
|
+
|
|
935
|
+
Start a run of any agent (hosted, workflow or code) with your own key; the run acts as you:
|
|
936
|
+
|
|
937
|
+
```python
|
|
938
|
+
import pac_agents as pac
|
|
939
|
+
|
|
940
|
+
pac.init()
|
|
941
|
+
run = pac.runs.create("support-bot", message="Where is my invoice?",
|
|
942
|
+
variables={"team": "billing"}, end_user="customer-42", wait=True)
|
|
943
|
+
print(run["status"], run["output"]) # a Run is the API's AgentInvocation (a dict)
|
|
944
|
+
pac.runs.get(run.id); pac.runs.wait(run.id, timeout_s=300)
|
|
945
|
+
pac.outcome(run.id, success=True, value_usd=12.5, minutes_saved=4) # the Value report
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
- An agent name is looked up once (and cached until the next `pac.init()`); an `agt_` id is used as
|
|
949
|
+
it is. Runs use the published version (the draft until the first publish); `version="draft"`, a
|
|
950
|
+
number, or `"staging"` (the staging version: edit level) picks another.
|
|
951
|
+
- `wait=True` returns once the run ended or waits for a person (an approval: it shows in the
|
|
952
|
+
console's Inbox, `/approvals`), at most `timeout_s` (120 s). A run start is never sent twice after
|
|
953
|
+
an error that may come after it started; only 429 and 503 are retried.
|
|
954
|
+
- `pac.outcome(run_id, success=..., value_usd=..., minutes_saved=..., note=...)` reports what a run
|
|
955
|
+
achieved (root runs that finished; the last report wins); the Value report counts it (Agents ›
|
|
956
|
+
Connections › Value, and the agent's Value card on Monitor › Charts).
|
|
957
|
+
- From the command line: `pac-agents runs start support-bot "Where is my invoice?" --var team=billing
|
|
958
|
+
--wait` (exit 0 succeeded, 1 failed or cancelled, 3 not finished), `runs get`, `runs wait`, `runs
|
|
959
|
+
outcome RUN_ID --success --value-usd 12.5`. `runs start` also takes `--end-user`, `--thread`,
|
|
960
|
+
`--version`, `--timeout` and `--json`, and `-` as the message reads it from stdin.
|
|
961
|
+
|
|
962
|
+
## Start runs with an agent API key
|
|
963
|
+
|
|
964
|
+
Your customers' traffic should not run as you. Give each agent its own API key (the agent's Settings
|
|
965
|
+
› Access › API keys, `pac_ak_...`): it reaches only that agent's runs, runs the published version as the agent,
|
|
966
|
+
within the key's limits (requests per minute, runs and dollars a day, allowed addresses, expiry).
|
|
967
|
+
|
|
968
|
+
```python
|
|
969
|
+
from pac_agents import AgentApi
|
|
970
|
+
|
|
971
|
+
api = AgentApi() # PAC_AGENT_KEY, PAC_BASE_URL
|
|
972
|
+
run = api.runs.create(message="Where is my invoice?", end_user="customer-42", wait=True)
|
|
973
|
+
print(run["status"], run["output"])
|
|
974
|
+
for event in api.runs.stream("And the one before?", end_user="customer-42", thread_id=run["threadId"]):
|
|
975
|
+
print(event["type"]) # run.started, llm.delta, tool.started...
|
|
976
|
+
api.outcome(run["id"], success=True) # a key with the outcomes scope
|
|
977
|
+
print(api.agent()["key"]) # the key's name, prefix, expiry and limits
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
`api.run(message, wait=True)`, `api.runs.get/wait/cancel(run_id)`, `api.runs.stream(message, ...)`
|
|
981
|
+
(the TypeScript SDK's spelling; `api.stream(...)` works too). The key comes from the argument
|
|
982
|
+
or `PAC_AGENT_KEY` (never from a URL), never shows in `repr()` or an error, and only goes to
|
|
983
|
+
`/api/agent-api/v1`. A personal token there answers "Use an agent API key (pac_ak_…) here." Errors
|
|
984
|
+
come back as `PacApiError` with Graticor's code: `invalid_agent_key`, `agent_key_expired`,
|
|
985
|
+
`agent_key_disabled`, `ip_not_allowed`, `not_published`, `agent_paused`, `run_as_unconfirmed`,
|
|
986
|
+
`rate_limited`, `key_daily_limit`, `key_busy`. Starting a run (and the stream) is retried only on 429 and 503, reads also on 5xx, up to
|
|
987
|
+
`retries` times (`AgentApi(retries=3)` by default, as the TypeScript `agentApi`), after the wait
|
|
988
|
+
`Retry-After` asks for; an answer that asks for more than 30 s (a key's daily cap lasts
|
|
989
|
+
until midnight UTC) raises its `PacApiError` at once instead of waiting. Keys are server-side
|
|
990
|
+
secrets: never ship one in a browser or an app.
|
|
991
|
+
|
|
992
|
+
### Keys from the command line
|
|
993
|
+
|
|
994
|
+
`pac-agents keys` manages an agent's keys on the same routes as Settings › Access › API keys (a
|
|
995
|
+
personal token with full scope: an Agents SDK key or a config token can't):
|
|
996
|
+
|
|
997
|
+
```bash
|
|
998
|
+
pac-agents keys list support-bot # NAME, PREFIX, STATUS, LAST USED, EXPIRES (in 9 days)
|
|
999
|
+
KEY=$(pac-agents keys create support-bot --name prod-server --expires 90) # the key alone on stdout
|
|
1000
|
+
pac-agents keys create support-bot --name ci --scope runs --rpm 120 -o key.txt
|
|
1001
|
+
pac-agents keys rotate support-bot prod-server --grace 24 -o key.txt
|
|
1002
|
+
pac-agents keys revoke support-bot pac_ak_AbCdE --yes
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
- A new key is shown once: alone on stdout, or written to `-o FILE` (readable by you only on Linux
|
|
1006
|
+
and macOS; on Windows the file keeps its folder's permissions); the note goes to stderr, and the
|
|
1007
|
+
key never appears in an error. `--json` prints Graticor's answer, the key included.
|
|
1008
|
+
- `create` sends only the flags you give (`--expires 30|90|365|never` or `--expires-in-days N`,
|
|
1009
|
+
`--scope runs|a2a|outcomes|mcp`, `--rpm`, `--runs-a-day`, `--usd-a-day`, `--allow-ip`); Graticor's
|
|
1010
|
+
defaults apply to the rest. A key that never expires needs owner level on the agent.
|
|
1011
|
+
- `rotate` and `revoke` take the key's id, its prefix or its name among the live keys. `rotate`
|
|
1012
|
+
keeps the old key working for `--grace` hours (default 24, 0 to 720). `revoke` asks first on a
|
|
1013
|
+
terminal ("Requests with it fail at once."); in a script it needs `--yes`.
|
|
1014
|
+
- Exit codes: 0 ok, 1 refused (a key that does not resolve, or Graticor's refusal: revoked, expired,
|
|
1015
|
+
already rotated), 2 bad usage or a Graticor error.
|
|
1016
|
+
|
|
1017
|
+
Rotation in a deploy script: the old key keeps working during the grace, so nothing fails while the
|
|
1018
|
+
new one rolls out.
|
|
1019
|
+
|
|
1020
|
+
```bash
|
|
1021
|
+
pac-agents keys rotate support-bot prod-server --grace 24 -o key.txt
|
|
1022
|
+
deploy --set PAC_AGENT_KEY="$(cat key.txt)" && rm key.txt # your deploy step
|
|
1023
|
+
```
|
|
1024
|
+
|
|
1025
|
+
## Reviewing memories
|
|
1026
|
+
|
|
1027
|
+
With memory review on ("Check first" in the agent's Memory settings), memories the model writes
|
|
1028
|
+
wait until one of the agent's reviewers accepts, edits or rejects them. In the console they wait in
|
|
1029
|
+
the agent's Monitor › Memory and in the Inbox (`/approvals`):
|
|
1030
|
+
|
|
1031
|
+
```python
|
|
1032
|
+
mem = pac.memories("support-bot") # or definition.memories, agent.memories
|
|
1033
|
+
queue = mem.review_queue() # {"summary", "items", "next"}, oldest first
|
|
1034
|
+
for m in mem.pending(): # every pending memory, page by page
|
|
1035
|
+
if "refund" in m["content"]:
|
|
1036
|
+
mem.reject(m["id"], note="We never promise refunds.")
|
|
1037
|
+
else:
|
|
1038
|
+
mem.accept(m["id"], kind="preference") # edit then accept: content, kind, importance...
|
|
1039
|
+
mem.history(memory_id) # every change, with before/after snapshots
|
|
1040
|
+
pac.runs.get(run_id).memory_diff() # what one run recalled and changed
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
These need `agents.write` and edit level on the agent. Bulk changes and restores stay in the console.
|
|
1044
|
+
|
|
1045
|
+
## Configuration reference
|
|
1046
|
+
|
|
1047
|
+
`pac.init()` arguments win over environment variables, which win over defaults.
|
|
1048
|
+
|
|
1049
|
+
| Environment | `init()` argument | Default | Meaning |
|
|
1050
|
+
|---|---|---|---|
|
|
1051
|
+
| `PAC_API_KEY` | `api_key` | none | personal token (Agents SDK scope recommended), sent as a Bearer token |
|
|
1052
|
+
| `PAC_BASE_URL` | `base_url` | `http://localhost:8787` | Graticor API origin |
|
|
1053
|
+
| `PAC_ACCOUNT` | `account` | the token's account | account id for an organization (`x-pac-account`) |
|
|
1054
|
+
| `PAC_AGENT_NAME` | `agent` | none | default agent name for `pac.agent()` and the CLI |
|
|
1055
|
+
| `PAC_ENV` | `environment` | `dev` | environment on traces; `dev` reads the draft, `staging` the staging version (the published one while the agent has none), anything else the published version |
|
|
1056
|
+
| `PAC_AGENT_VERSION` | `agent_version` | from the environment | `draft`, `published`, `staging` or a version number |
|
|
1057
|
+
| `PAC_AGENT_KEY` | `AgentApi(key)` | none | an agent's own API key (`pac_ak_...`) for `pac.AgentApi` |
|
|
1058
|
+
| `PAC_CAPTURE_CONTENT` | `capture_content` | `1` | `0` keeps prompts and outputs out of traces |
|
|
1059
|
+
| `PAC_ALLOW_INSECURE` | `allow_insecure` | `0` | allow plain `http://` to a host other than localhost |
|
|
1060
|
+
| `PAC_EXPORT_ALL_SPANS` | `export_all_spans` | `0` | `1` sends every span of the process, not only agent traces |
|
|
1061
|
+
| `PAC_OFFLINE` | `offline` | `0` | `1` sends nothing to Graticor (no registration, config pull or span export) |
|
|
1062
|
+
| | `instrument` | `"auto"` | instrumentors to enable: `"auto"`, a list of names, or `False` |
|
|
1063
|
+
| | `disable_openai_tracing` | `None` | OpenAI Agents SDK: `True` traces to Graticor only; `None` also when its exporter has no OpenAI key; `False` leaves it alone |
|
|
1064
|
+
| | `tracer_provider` | the global one | attach to this TracerProvider |
|
|
1065
|
+
| | `span_exporter` | Graticor OTLP | replace the exporter (tests, debugging) |
|
|
1066
|
+
| | `timeout`, `export_timeout` | 30 s, 10 s | API request and OTLP export timeouts |
|
|
1067
|
+
|
|
1068
|
+
The SDK sets `OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental` and
|
|
1069
|
+
`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=SPAN_ONLY` when content capture is on and you
|
|
1070
|
+
did not set them yourself. Agent names use lowercase letters, digits, `-` and `_` (max 63).
|
|
1071
|
+
|
|
1072
|
+
Waits on Graticor stay short where your code is waiting: the registration `pac.agent()` makes at
|
|
1073
|
+
import waits at most 5 seconds, a config pull from `agent.instructions` / `agent.param()` at most
|
|
1074
|
+
5 seconds without retry (other threads get the copy they have meanwhile, and a failed pull is not
|
|
1075
|
+
retried for a few seconds), and `pac.flush(timeout)` keeps to its timeout. `agent.config(refresh=True)`
|
|
1076
|
+
uses the full `timeout` with a retry.
|
|
1077
|
+
|
|
1078
|
+
## Command line
|
|
1079
|
+
|
|
1080
|
+
```text
|
|
1081
|
+
pac-agents whoami who the key belongs to, the account, the key's scope (Key line), what it may do
|
|
1082
|
+
pac-agents serve module:attr [--name NAME] [--concurrency N]
|
|
1083
|
+
run a worker (Agent, LangGraph graph, crew, OpenAI agent, function)
|
|
1084
|
+
pac-agents eval module:attr --dataset D [--evaluator ID]... [--gate ID=0.8]... [--repetitions N]
|
|
1085
|
+
[--concurrency N] [--experiment NAME] [--name NAME]
|
|
1086
|
+
pac-agents eval --on-pac AGENT --dataset D [--gate ID=0.8]... [--version V] [--timeout S]
|
|
1087
|
+
Graticor runs the experiment; this waits and gates (exit 3: still running)
|
|
1088
|
+
pac-agents graph module:attr [--push] print the architecture graph, or register it
|
|
1089
|
+
pac-agents pull AGENT [-o FILE] [--version draft|published|N] [--format json|python]
|
|
1090
|
+
the agent as AGENT.agent.json (or AGENT.agent.py)
|
|
1091
|
+
pac-agents push FILE [--name NAME] [--force] [--dry-run] [--drop-unresolved] [--publish [NOTE]]
|
|
1092
|
+
[--stage staging|production]
|
|
1093
|
+
create or update agents from an .agent.json or a .py
|
|
1094
|
+
pac-agents promote AGENT [--version N] [--note NOTE]
|
|
1095
|
+
the staging version (or N) to production
|
|
1096
|
+
pac-agents workflow pull|push|diff|validate AGENT [FILE]
|
|
1097
|
+
a workflow agent's steps as a file
|
|
1098
|
+
pac-agents keys list|create|rotate|revoke AGENT ...
|
|
1099
|
+
an agent's API keys (a new key is shown once)
|
|
1100
|
+
pac-agents runs start AGENT MESSAGE [--var NAME=VALUE]... [--wait] | get RUN | wait RUN | outcome RUN
|
|
1101
|
+
runs with your key
|
|
1102
|
+
pac-agents skills from-run TRACE_ID [-o FOLDER] [--import]
|
|
1103
|
+
a skill drafted from a successful run
|
|
1104
|
+
pac-agents sandbox ... the sandbox daemon (Linux or WSL)
|
|
1105
|
+
pac-agents --version the package version (pac-agents 0.2.0)
|
|
1106
|
+
```
|
|
1107
|
+
|
|
1108
|
+
`pac-agents skills from-run TRACE_ID [-o FOLDER] [--import]` drafts a skill from a successful run
|
|
1109
|
+
(the files, the scan and notes; `--import` adds it to the account's skills): it needs a personal
|
|
1110
|
+
token with full scope. It also takes `--skill SKILL_ID` (a new version of that skill),
|
|
1111
|
+
`--focus TEXT` (300 characters at most), `--include-scripts`, `--include-example` and
|
|
1112
|
+
`--changelog`. `python -m pac_agents.cli_config skills from-run TRACE_ID` does the same.
|
|
1113
|
+
|
|
1114
|
+
Exit codes of the config and run commands: 0 ok; 1 refused (names not in the account, a draft
|
|
1115
|
+
changed since the pull, validation errors, readiness or staging blocks a publish, a promotion Graticor
|
|
1116
|
+
refuses, a failed run, differences found by `workflow diff`); 2 bad usage or a Graticor error (for
|
|
1117
|
+
example an Agents SDK key on a push); 3 a run that has not finished (it waits for a person, or the
|
|
1118
|
+
timeout passed).
|
|
1119
|
+
|
|
1120
|
+
`module` is a module path (`my_app.agent`) or a file (`agent.py`, imported with its own directory
|
|
1121
|
+
first on `sys.path`, as `python agent.py` would, so its sibling imports work); without `:attr`
|
|
1122
|
+
the module's first `Agent` is used. Global options, given before the command: `--base-url`,
|
|
1123
|
+
`--account`, `--env`, `--config-version`, `--allow-insecure`, `-v`, `--version`. The key is read
|
|
1124
|
+
from `PAC_API_KEY` only, never from the command line. The agent of a target that is not an
|
|
1125
|
+
`Agent`: see [Serving](#serving-the-worker). Exit codes: 0 ok, 1 gate failed or command
|
|
1126
|
+
failed (no graph found), 2 bad usage (a bad option such as `--repetitions 11`, a module that
|
|
1127
|
+
fails to import: the message names the error, `-v` shows the traceback, an object several agents
|
|
1128
|
+
own without `--name`) or Graticor error, 130 interrupted.
|
|
1129
|
+
|
|
1130
|
+
## The sandbox daemon (Linux or WSL)
|
|
1131
|
+
|
|
1132
|
+
`pac-agents sandbox` runs Graticor agents' sandboxes on a machine of yours: a **Your infrastructure**
|
|
1133
|
+
runtime (Agents › Connections › Runtimes › the runtime › Connect a machine shows the exact command),
|
|
1134
|
+
a **Graticor sandbox host** (`--platform`, added by a platform operator in Operate › Sandbox hosts,
|
|
1135
|
+
`/admin/sandbox-hosts`), or the machine Graticor rents for a dedicated runtime (its bootstrap starts
|
|
1136
|
+
it). It connects out to Graticor over https and pulls work; Graticor never connects to it.
|
|
1137
|
+
|
|
1138
|
+
**What the server needs (as of 2026-11-06).** Each of the three is gated on the Graticor server:
|
|
1139
|
+
|
|
1140
|
+
- every kind needs the wheel (`PAC_SANDBOX_DAEMON_WHEEL`; unset, the commands answer 409
|
|
1141
|
+
`daemon_package_missing`) and a `PAC_PUBLIC_API_URL` on https (http only for localhost; else 409
|
|
1142
|
+
`public_url_missing`);
|
|
1143
|
+
- sandbox hosts run agents' sandboxes only with `PAC_SANDBOX_DRIVER=sandbox_host`, and a host must
|
|
1144
|
+
run the Docker backend with gVisor (409 `platform_needs_isolation` otherwise);
|
|
1145
|
+
- dedicated machines also need live rentals (`PAC_LIVE_RENTALS=1`; else 403 `live_rentals_off`) and
|
|
1146
|
+
confirmed machine pins (`PAC_MACHINE_PYTHON_IMAGE` and `PAC_MACHINE_RUNSC_SHA256`; else 409
|
|
1147
|
+
`machine_pins_unconfirmed`).
|
|
1148
|
+
|
|
1149
|
+
The production files in this repository (`deploy/prod/`) set the https public URL but no wheel and
|
|
1150
|
+
no sandbox driver, and keep live rentals off, so a server deployed from them runs no sandboxes and
|
|
1151
|
+
rents no machines. `docs/AGENTS.md` ("Before production") records the daemon's Linux tests
|
|
1152
|
+
(`npm run test:daemon-linux`: 29 passed on 2026-11-01) and one real daemon on the process backend
|
|
1153
|
+
against a local Graticor. A sandbox host with gVisor and a rented machine with a co-located model
|
|
1154
|
+
are listed there as not run on a real system yet.
|
|
1155
|
+
|
|
1156
|
+
**Install.** Graticor serves the daemon package itself: the command the console shows downloads the
|
|
1157
|
+
wheel from your Graticor (`/api/agents/runtime/daemon/package/<file>`), checks its sha256 with
|
|
1158
|
+
`sha256sum -c`, installs that file in a virtual environment and starts the daemon. It is never
|
|
1159
|
+
installed from PyPI by name. The operator builds the wheel with `node scripts/build-daemon-wheel.mjs`
|
|
1160
|
+
(this package, version 0.2.0) and points `PAC_SANDBOX_DAEMON_WHEEL` at it; the machines list says
|
|
1161
|
+
"Update available" for daemons older than the configured wheel. **Updating** needs no new code:
|
|
1162
|
+
"Update it" shows a command that reads the machine's own token from its state directory
|
|
1163
|
+
(`daemon.json`) into curl's stdin (the package route accepts it), checks the sha256, reinstalls the
|
|
1164
|
+
package and restarts the daemon the way it runs (service, terminal or Docker). Nobody is emailed.
|
|
1165
|
+
|
|
1166
|
+
**Enroll once.** The one-use code Graticor shows (it starts with `pace_`) is read from a file
|
|
1167
|
+
(`--enroll-file PATH`, deleted after enrolling), stdin (`--enroll-file -`; the console's command
|
|
1168
|
+
types it at a `read -rs` prompt), `PAC_SANDBOX_ENROLL_FILE`, or `PAC_SANDBOX_ENROLL_TOKEN` (removed
|
|
1169
|
+
from the environment once read). It is never read from the command line (`--enroll pace_...` is
|
|
1170
|
+
refused). The daemon then keeps its
|
|
1171
|
+
token and instance key in its state directory (0700: `/var/lib/pac-sandbox` as root, else
|
|
1172
|
+
`~/.local/state/pac-agents/sandbox`; `daemon.json` 0600), and later starts reuse it.
|
|
1173
|
+
|
|
1174
|
+
```bash
|
|
1175
|
+
pac-agents sandbox --base-url https://api.example.com --enroll-file /etc/pac/sandbox.enroll \
|
|
1176
|
+
--name build-01 --backend auto
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
| Flag | Meaning |
|
|
1180
|
+
|---|---|
|
|
1181
|
+
| `--base-url URL` | the Graticor API (`PAC_BASE_URL`); https only, http only for localhost with `--insecure-localhost` |
|
|
1182
|
+
| `--enroll-file PATH\|-` | the one-use code (`PAC_SANDBOX_ENROLL_FILE`) |
|
|
1183
|
+
| `--insecure-localhost` | allow `http://localhost` (development only) |
|
|
1184
|
+
| `--name NAME` | how the machine shows in the console (default: the host name) |
|
|
1185
|
+
| `--backend auto\|docker\|process` | the isolation (`PAC_SANDBOX_BACKEND`; `auto`: Docker when it answers for this user) |
|
|
1186
|
+
| `--state-dir DIR` | where the token, sessions and idempotency records live (`PAC_SANDBOX_STATE_DIR`) |
|
|
1187
|
+
| `--max-sessions N` | sandboxes at once (`PAC_SANDBOX_MAX_SESSIONS`; default (memory − 2 GB) / 2 GB) |
|
|
1188
|
+
| `--allow-image KIND=IMAGE` | another image for a kind: `python`, `node`, `python-node` or `browser` (repeatable; `PAC_SANDBOX_ALLOW_IMAGES`, a comma list), e.g. `browser=<image@sha256:...>` |
|
|
1189
|
+
| `--allow-same-user` | process backend without root: every sandbox runs as this user (shown as "Shared user"; Graticor then blocks agents that people outside the company reach) |
|
|
1190
|
+
| `--workspace-days N` | delete conversation workspaces untouched this many days (7) |
|
|
1191
|
+
| `--engine-container NAME` | the co-located model's container, which Graticor may restart ("Reload the model" on a dedicated machine; Docker backend). Graticor's machine bootstrap passes `pac-engine`; without it the daemon answers that it runs no model Graticor can reload |
|
|
1192
|
+
| `--platform` | enroll as a Graticor sandbox host (needs the Docker backend with gVisor `runsc`) |
|
|
1193
|
+
| `--check` | print what isolation and network enforcement this machine gives, and exit |
|
|
1194
|
+
| `--once` | one poll, then exit (diagnostics) |
|
|
1195
|
+
|
|
1196
|
+
**Backends.**
|
|
1197
|
+
|
|
1198
|
+
- `docker`: full isolation, with exactly the hardening of Graticor's own sandboxes (no capabilities, a
|
|
1199
|
+
non-root user, a read-only root, CPU, memory and process limits), gVisor (`runsc`) when installed,
|
|
1200
|
+
and network rules enforced through the egress proxy Graticor serves. Conversation workspaces stay on
|
|
1201
|
+
the machine's disk between sessions. It runs the browser image too (`--shm-size 512m`, with the
|
|
1202
|
+
verified helpers copied in).
|
|
1203
|
+
- `process`: basic isolation for machines without Docker. As root each session runs under its own
|
|
1204
|
+
system user (`pac-sbx-<n>`) with its own 0700 workspace, rlimits, a scrubbed environment, its
|
|
1205
|
+
process group killed at the timeout, and network `none` / `setup` enforced with a network
|
|
1206
|
+
namespace; pip installs into a per-environment venv, npm into a prefix, apt is refused ("System
|
|
1207
|
+
packages need the Docker backend."), and the browser image is refused. Other network modes are
|
|
1208
|
+
advisory here.
|
|
1209
|
+
|
|
1210
|
+
**Network.** The daemon's egress proxies refuse private and metadata addresses, every address of
|
|
1211
|
+
this machine (its interfaces, the default route's source, its host names) and Graticor's, plus
|
|
1212
|
+
`PAC_SANDBOX_DENY_ADDRESSES` (for a NAT's public address). A Your-infrastructure runtime's
|
|
1213
|
+
**private systems** are the exception you list in the console. A Graticor sandbox host never receives
|
|
1214
|
+
private systems.
|
|
1215
|
+
|
|
1216
|
+
**Signing requests with a secret.** No daemon ever holds a secret's value. When an environment signs
|
|
1217
|
+
requests with a secret, the daemon's egress proxy hands those requests to Graticor's signing relay
|
|
1218
|
+
(`POST /api/agents/runtime/daemon/relay`, a `pacr_` ticket), which adds the secret on the server. The
|
|
1219
|
+
daemon gets only the host and header names, the certificates and the ticket. Only the Docker backend
|
|
1220
|
+
can relay; such sandboxes start only on machines that can (`apps/api/src/agents/environments/relay.ts`,
|
|
1221
|
+
`daemon/remote.ts`).
|
|
1222
|
+
|
|
1223
|
+
**Safe to repeat.** Before it runs a keyed operation the daemon records `{key, state, result}` in
|
|
1224
|
+
its state directory, per environment, so a call Graticor sends again after its own restart gets the
|
|
1225
|
+
first result instead of running twice; a key started without a result answers `outcome_unknown`.
|
|
1226
|
+
|
|
1227
|
+
**As a service.** The console's "How should it run?" offers three ways, each with a command that
|
|
1228
|
+
checks the machine (`--check`) before it enrolls it and a restart command that needs no code. **As a
|
|
1229
|
+
service** (recommended) installs the package in `/opt/pac-sandbox`, writes the code to
|
|
1230
|
+
`/etc/pac/sandbox.enroll` (0600; the daemon deletes it once enrolled), keeps the state in
|
|
1231
|
+
`/var/lib/pac-sandbox` and installs `pac-sandbox.service` (the same unit name as the rented
|
|
1232
|
+
machines' bootstrap) with `Restart=on-failure` and `RestartPreventExitStatus=2 3`, so a refused code
|
|
1233
|
+
or a revoked machine does not loop; start it again with `sudo systemctl restart pac-sandbox`. **In
|
|
1234
|
+
this terminal** runs `~/.pac-sandbox/bin/pac-agents sandbox` until the terminal closes; start it again
|
|
1235
|
+
with the same line without `--enroll-file`. **In Docker** (Docker backend only) runs the daemon in
|
|
1236
|
+
`docker:27-cli` with `--network host`, the host's Docker socket and the state directory at the same
|
|
1237
|
+
path inside and outside; start it again with `docker start pac-sandbox` (the `docker:27-cli` image
|
|
1238
|
+
is not pinned by digest yet: a TODO in `apps/api/src/agents/environments/daemon/package.ts`). Without Docker the commands
|
|
1239
|
+
start `--backend process` with `sudo`, so each sandbox gets a user of its own. `SIGTERM` stops polling, finishes running operations
|
|
1240
|
+
for up to 30 s and says goodbye to Graticor. Exit codes: 0 stopped, 2 enrollment refused or bad usage, 3
|
|
1241
|
+
revoked. Logs have one line per operation (kind, ids, duration, ok), never code, contents, outputs
|
|
1242
|
+
or tokens; `HTTPS_PROXY` is honoured, redirects are refused.
|
|
1243
|
+
|
|
1244
|
+
The daemon's backends need POSIX: on Windows the command stops with "Run the sandbox daemon on
|
|
1245
|
+
Linux (or WSL).", and every other command works there. See `pac-agents sandbox --help`.
|
|
1246
|
+
|
|
1247
|
+
**On Windows.** Run it in WSL (the console's "On Windows (WSL)" fold has the same steps): in
|
|
1248
|
+
PowerShell as administrator `wsl --install -d Ubuntu`, restart and open Ubuntu; in Ubuntu
|
|
1249
|
+
`sudo apt update && sudo apt install -y python3-venv curl`; for full isolation turn on WSL
|
|
1250
|
+
integration for Ubuntu in Docker Desktop (or `sudo apt install -y docker.io && sudo usermod -aG
|
|
1251
|
+
docker $USER`, then reopen Ubuntu); for the service, turn on systemd
|
|
1252
|
+
(`grep -qs '^systemd=true' /etc/wsl.conf || printf '[boot]\nsystemd=true\n' | sudo tee -a /etc/wsl.conf`,
|
|
1253
|
+
then `wsl --shutdown` in PowerShell).
|
|
1254
|
+
Run the console's command in Ubuntu, not in PowerShell; the laptop must stay on and awake for the
|
|
1255
|
+
agents' tools to run.
|
|
1256
|
+
|
|
1257
|
+
## Examples
|
|
1258
|
+
|
|
1259
|
+
All examples read `PAC_*` from the environment, run on the Simulated model until you assign
|
|
1260
|
+
another one, and print the agent's console page and the trace link. Against a local dev API they
|
|
1261
|
+
need no model key, except `anthropic_tools.py` (your own `ANTHROPIC_API_KEY`); install each
|
|
1262
|
+
example's framework first (`pip install langgraph`, `crewai`, `openai-agents`,
|
|
1263
|
+
`llama-index-workflows`...). `llamaindex_rag.py` reads the knowledge base named by `PAC_KB`
|
|
1264
|
+
(default `docs`) and `evaluate_ci.py` the dataset named by `PAC_DATASET` (default `faq-smoke`):
|
|
1265
|
+
create them in the console first.
|
|
1266
|
+
|
|
1267
|
+
| File | Shows |
|
|
1268
|
+
|---|---|
|
|
1269
|
+
| [`quickstart_openai.py`](examples/quickstart_openai.py) | the OpenAI client on the router, a session |
|
|
1270
|
+
| [`langgraph_agent.py`](examples/langgraph_agent.py) | a StateGraph with a ToolNode, two slots, a param, register, `--serve` |
|
|
1271
|
+
| [`crewai_crew.py`](examples/crewai_crew.py) | a two-agent crew with a slot per agent |
|
|
1272
|
+
| [`openai_agents_handoffs.py`](examples/openai_agents_handoffs.py) | triage with handoffs, one slot per agent |
|
|
1273
|
+
| [`llamaindex_rag.py`](examples/llamaindex_rag.py) | a LlamaIndex Workflow over a Graticor knowledge base, with citations |
|
|
1274
|
+
| [`anthropic_tools.py`](examples/anthropic_tools.py) | the Anthropic SDK with your own key and a tool loop, traced to Graticor |
|
|
1275
|
+
| [`worker_serve.py`](examples/worker_serve.py) | a worker with memory, a tool, a param and logs |
|
|
1276
|
+
| [`evaluate_ci.py`](examples/evaluate_ci.py) | `pac.evaluate` with gates and CI exit codes |
|
|
1277
|
+
|
|
1278
|
+
## Troubleshooting
|
|
1279
|
+
|
|
1280
|
+
**"Could not reach Graticor at ... Is it running?"** The API is not at `PAC_BASE_URL`. Your app keeps
|
|
1281
|
+
running; spans are dropped and registration is retried on the next config pull or `serve()`.
|
|
1282
|
+
|
|
1283
|
+
**"Refusing to send the Graticor API key over plain http"** `PAC_BASE_URL` is `http://` to another
|
|
1284
|
+
machine. Use https, or set `PAC_ALLOW_INSECURE=1` on a trusted network.
|
|
1285
|
+
|
|
1286
|
+
**"Graticor answered with a non-JSON body (text/html)"** `PAC_BASE_URL` points at the web console (or
|
|
1287
|
+
a proxy page), not at the API. Use the API's origin (`http://localhost:8787` in development).
|
|
1288
|
+
|
|
1289
|
+
**401 / 403 `token_scope`.** The key is wrong, revoked, or its scope does not cover the call
|
|
1290
|
+
(an Agents SDK key reaches only the routes the package calls). With an organization account, set
|
|
1291
|
+
`PAC_ACCOUNT`. Check with `pac-agents whoami`: its `Key` line says what the key itself can do
|
|
1292
|
+
(Agents SDK, Agent configs, Read only or Full). `pac-agents push`, `workflow push` and `--publish`
|
|
1293
|
+
write drafts: they need a config token (Agent configs) or a personal token with full scope;
|
|
1294
|
+
`skills from-run` needs full scope.
|
|
1295
|
+
|
|
1296
|
+
**"The draft of ... changed since you pulled it".** Someone saved the agent (or its workflow) in the
|
|
1297
|
+
console after your pull. `pac-agents workflow diff AGENT FILE` shows what your push would change;
|
|
1298
|
+
pull again and redo your edit, or push with `--force` to replace what they saved.
|
|
1299
|
+
|
|
1300
|
+
**A push fails with names that are "not in this account".** The file names a knowledge base,
|
|
1301
|
+
agent, model connection... that this account does not have (files move between accounts by
|
|
1302
|
+
name). Create it, rename it to match, or push with `--drop-unresolved` and pick it in the console.
|
|
1303
|
+
|
|
1304
|
+
**409 `model_not_assigned`.** Neither the slot nor the agent's main model is set. Pick one in the
|
|
1305
|
+
console (Build > Models). A brand new code agent starts on the Simulated model.
|
|
1306
|
+
|
|
1307
|
+
**The answers start with "[simulated]"** (followed by lorem ipsum, or "Based on <tool>: …" after a
|
|
1308
|
+
tool call). The agent (or that slot) still uses the Simulated model, or a Graticor deployment that
|
|
1309
|
+
is a dry run (the server runs without `PAC_DEPLOY_EXECUTE=1`).
|
|
1310
|
+
|
|
1311
|
+
**Console edits do not apply.** The code reads the published version: set `PAC_ENV=dev` or
|
|
1312
|
+
`PAC_AGENT_VERSION=draft`, or publish. Config is cached for 60 seconds (`agent.config(refresh=True)`
|
|
1313
|
+
forces a pull).
|
|
1314
|
+
|
|
1315
|
+
**"PAC_ENV is not set: this process reads the draft of ...; v3 is published."** The code runs
|
|
1316
|
+
without `PAC_ENV`, so it reads the draft, edits nobody published included. On a production server
|
|
1317
|
+
set `PAC_ENV=prod` (it then reads the published version). On a dev machine set `PAC_ENV=dev` to
|
|
1318
|
+
keep the draft and silence the warning.
|
|
1319
|
+
|
|
1320
|
+
**"No worker is connected for ..."** Start one: `pac-agents serve module:attr`. Check that the
|
|
1321
|
+
worker uses the same account and agent name as the console page (the Playground shows the
|
|
1322
|
+
connected workers; the worker logs the agent it serves, `--name` picks it).
|
|
1323
|
+
|
|
1324
|
+
**"OPENAI_API_KEY is not set, skipping trace export"** comes from the OpenAI Agents SDK's own
|
|
1325
|
+
exporter to OpenAI. `pac.init(disable_openai_tracing=True)` removes it; the default does so too
|
|
1326
|
+
once the SDK is imported, unless an OpenAI key is set for it.
|
|
1327
|
+
|
|
1328
|
+
**No graph in Build › Graph or Monitor › Charts.** The object was not recognised, or the adapter could not read it
|
|
1329
|
+
(see the warning). Run `pac-agents graph module:attr` to check, or register a dict. The observed
|
|
1330
|
+
graph appears after the first traces either way.
|
|
1331
|
+
|
|
1332
|
+
**No LLM spans.** The framework's instrumentor is not installed: add the matching extra (for
|
|
1333
|
+
example `pip install "graticor[anthropic]"`). `pac.init(instrument=[...])` with an unknown
|
|
1334
|
+
name logs the known ones. Turn on `-v` (CLI) or `logging.getLogger("pac_agents").setLevel("DEBUG")`.
|
|
1335
|
+
|
|
1336
|
+
**Traces show "Content hidden for your role".** Your role lacks `agents.write`; ask an admin.
|
|
1337
|
+
"Content hidden" with that permission: the agent keeps metadata only (agent › Settings › Data &
|
|
1338
|
+
advanced › Trace content), or the code ran with `PAC_CAPTURE_CONTENT=0`.
|
|
1339
|
+
|
|
1340
|
+
## Development
|
|
1341
|
+
|
|
1342
|
+
```bash
|
|
1343
|
+
python3 -m venv .venv && . .venv/bin/activate # Windows: py -3.13 -m venv .venv; .venv\Scripts\activate
|
|
1344
|
+
pip install -e "sdks/python[dev]"
|
|
1345
|
+
pytest sdks/python/tests
|
|
1346
|
+
```
|
|
1347
|
+
|
|
1348
|
+
There are 42 test files in `tests/`. Tests never call a real network: the Graticor API is faked
|
|
1349
|
+
with `httpx.MockTransport` or a loopback server on 127.0.0.1 (which also plays the model router and
|
|
1350
|
+
decodes OTLP). Tests of a framework adapter use small fakes and, when the framework is installed,
|
|
1351
|
+
real objects too.
|
|
1352
|
+
|
|
1353
|
+
The publishing workflow (`.github/workflows/publish-python.yml`) runs these tests before each release;
|
|
1354
|
+
CI on pull requests does not (`.github/workflows/ci.yml` runs the TypeScript SDK's). Run them
|
|
1355
|
+
yourself before you change the package. The sandbox daemon's backend tests (`test_sandbox_process`,
|
|
1356
|
+
`test_sandbox_docker`) are Linux-only and skipped on Windows; its protocol tests
|
|
1357
|
+
(`test_sandbox_daemon`) run everywhere. `npm run test:daemon-linux` from the repository root runs
|
|
1358
|
+
all three files on Linux, or inside a local `python:3.12-slim` container elsewhere (it never pulls
|
|
1359
|
+
the image; `scripts/daemon-linux-tests.mjs`).
|
|
1360
|
+
|
|
1361
|
+
`tests/test_live_api.py` runs the same paths against a real Graticor API (router, LangGraph graph and
|
|
1362
|
+
traces, a worker serving a playground chat, knowledge, memory, evaluations and the CLI, params and
|
|
1363
|
+
slots). It is skipped unless you point it at one; a local dev API needs no model key, since new
|
|
1364
|
+
code agents use the Simulated model:
|
|
1365
|
+
|
|
1366
|
+
```bash
|
|
1367
|
+
export PAC_SDK_E2E_URL=http://127.0.0.1:8787 # the API (npm run dev:api from the repository root)
|
|
1368
|
+
export PAC_SDK_E2E_KEY=pac_... # a token with the Agents SDK scope
|
|
1369
|
+
# PAC_SDK_E2E_ADMIN_KEY=pac_... # a full-scope token for the checks, when dev auth is off
|
|
1370
|
+
pytest sdks/python/tests/test_live_api.py
|
|
1371
|
+
```
|