@mistralai-capabilities/backend-agents 0.0.0-stage → 0.1.88
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.
- package/.templateignore +27 -0
- package/CHANGELOG.md +235 -0
- package/LICENSE +201 -0
- package/capability.json +41 -0
- package/package/py/LICENSE +201 -0
- package/package/py/pyproject.toml +28 -0
- package/package/py/src/mistralai_capabilities/agents/__init__.py +2 -0
- package/package/py/src/mistralai_capabilities/agents/assembly.py +171 -0
- package/package/py/src/mistralai_capabilities/agents/hook_chain.py +184 -0
- package/package/py/src/mistralai_capabilities/agents/tools.py +16 -0
- package/package.json +7 -4
- package/template/apps/agent/project.json +29 -0
- package/template/apps/agent/pyproject.toml +54 -0
- package/template/apps/agent/src/agent/__init__.py +2 -0
- package/template/apps/agent/src/agent/connectors/__init__.py +9 -0
- package/template/apps/agent/src/agent/hooks/__init__.py +13 -0
- package/template/apps/agent/src/agent/instructions/README.md +1 -0
- package/template/apps/agent/src/agent/instructions.md +7 -0
- package/template/apps/agent/src/agent/main.py +30 -0
- package/template/apps/agent/src/agent/mcps/__init__.py +7 -0
- package/template/apps/agent/src/agent/skills/README.md +1 -0
- package/template/apps/agent/src/agent/subagents/__init__.py +7 -0
- package/template/apps/agent/src/agent/tools/__init__.py +7 -0
- package/template/apps/agent/tests/test_agent.py +111 -0
- package/template/deploy/docker/Dockerfile.agent +61 -0
- package/template/main.py +13 -0
- package/template/packages/py/env/src/env/agents.py +48 -0
- package/README.md +0 -3
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# The app's agent: an Agents SDK project the SDK's CLI loads from `[tool.mistralai.agents]` below,
|
|
2
|
+
# served locally by `agents serve` (`mistral dev`) and in production by `agents run-worker` (the agent
|
|
3
|
+
# image) or as a managed agent (`mistral agents deploy`). It is a member of the app's uv workspace, so
|
|
4
|
+
# the contributions other capabilities vendor into `src/agent/` import the app's packages (`env`,
|
|
5
|
+
# capability toolkits) the same way the worker does.
|
|
6
|
+
[project]
|
|
7
|
+
name = "agent"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
requires-python = ">=3.12,<3.15"
|
|
10
|
+
dependencies = [
|
|
11
|
+
# Exact-pinned in lockstep with the `agents` capability's package. `bashkit` is the files-only
|
|
12
|
+
# sandbox the skills run in (see `src/agent/main.py`). `mistralai-agents` is public on PyPI,
|
|
13
|
+
# so it resolves from the default index with no `[tool.uv.sources]` binding.
|
|
14
|
+
"mistralai-agents[bashkit]==1.1.3",
|
|
15
|
+
# `env` provides the typed settings: the agent's model and the settings the assembled tools read.
|
|
16
|
+
"env",
|
|
17
|
+
"pydantic>=2.14.1",
|
|
18
|
+
"mistralai>=3.6.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[dependency-groups]
|
|
22
|
+
# pytest + ty so the agent's own tests (`tests/`) and `agent:typecheck` run even when no optional
|
|
23
|
+
# capability brings its own test tooling; pytest-asyncio for the async tests that capabilities vendor
|
|
24
|
+
# there, which mark themselves (`asyncio_mode = auto` is set only when a capability provides it).
|
|
25
|
+
dev = [
|
|
26
|
+
"pytest>=9.1.1",
|
|
27
|
+
"pytest-asyncio>=1.4.0",
|
|
28
|
+
"ty>=0.0.86",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.13.0,<0.14.0"]
|
|
33
|
+
build-backend = "uv_build"
|
|
34
|
+
|
|
35
|
+
[tool.uv.build-backend]
|
|
36
|
+
module-name = "agent"
|
|
37
|
+
|
|
38
|
+
[tool.uv.sources]
|
|
39
|
+
env = { workspace = true }
|
|
40
|
+
|
|
41
|
+
# The SDK's CLI (`agents info|chat|serve|run-worker|deploy`, and `mistral agents ...`) loads the agent
|
|
42
|
+
# from this entrypoint (module:attr). It resolves through the installed `agent` package, so the CLI,
|
|
43
|
+
# the agent image and the worker's evals import the same module.
|
|
44
|
+
[tool.mistralai.agents]
|
|
45
|
+
entrypoint = "agent.main:agent"
|
|
46
|
+
|
|
47
|
+
[tool.ty.environment]
|
|
48
|
+
python-version = "3.14"
|
|
49
|
+
|
|
50
|
+
[tool.ty.src]
|
|
51
|
+
# Other capabilities vendor their contribution packages into `src/agent/`; each is
|
|
52
|
+
# covered by its own capability's tests, not by this check. Excluded here so the agent's own check
|
|
53
|
+
# never depends on an optional capability's toolkit being importable in this environment.
|
|
54
|
+
exclude = ['src/agent/tools/', 'src/agent/connectors/', 'src/agent/hooks/', 'src/agent/mcps/', 'src/agent/subagents/', 'src/agent/chat/']
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Connector contributions merged into the app agent.
|
|
2
|
+
|
|
3
|
+
Each installed capability that contributes an external-service connector vendors one ``<key>.py``
|
|
4
|
+
module here exposing a single module-level ``connector: agents.Connector`` (an
|
|
5
|
+
``agents.connector("<key>")`` slot -- one file per connector);
|
|
6
|
+
``mistralai_capabilities.agents.assembly`` merges them into the app agent's fields.
|
|
7
|
+
A module may set ``connector = None`` to opt out (e.g. a gated connector). See
|
|
8
|
+
``mistralai_capabilities.agents.assembly`` for the full contract.
|
|
9
|
+
"""
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Hook contributions merged into the app agent.
|
|
2
|
+
|
|
3
|
+
Each installed capability that contributes a lifecycle hook vendors one ``<hook>.py`` module here
|
|
4
|
+
exposing a single module-level ``hook: agents.Hook`` (stateless only -- the SDK rejects stateful
|
|
5
|
+
``agents.State`` hooks; one file per hook); ``mistralai_capabilities.agents.assembly`` merges them
|
|
6
|
+
into the app agent's fields. See ``mistralai_capabilities.agents.assembly`` for the
|
|
7
|
+
full contract.
|
|
8
|
+
|
|
9
|
+
Each stage runs the hooks in module-name order, except ``post_agent_turn``: several handlers are
|
|
10
|
+
chained (each sees the earlier replacements) in their class's ``post_agent_turn_order`` -- answer
|
|
11
|
+
shapers keep the default, a gate judging the final answer declares ``SAFETY`` to run last (see
|
|
12
|
+
``mistralai_capabilities.agents.hook_chain``).
|
|
13
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Instruction fragments merged into the app agent: each `<name>.md` here is appended, in name order, after `../instructions.md`. Use one for guidance that spans a capability's tools; a single tool's guidance belongs in its description. A `_`-prefixed fragment is skipped.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
You are this app's agent. Complete each request by calling the tools and connectors whose scope fits it, then synthesize their results into a single, concise final answer. Use only the tools and connectors you are actually given; if none fits, answer from the conversation and say so.
|
|
2
|
+
|
|
3
|
+
Plan before you call: decide what you need to know, gather it, and check that the results actually support your answer before you give it. For a request about a specific external system, prefer that system's connector when you have one. A tool result that is an execution handle or an identifier is an intermediate step, not a final answer.
|
|
4
|
+
|
|
5
|
+
Cite what you rely on. When a tool result carries a source link, cite it inline as a Markdown link, `[title](url)`, at the claim it supports, using the url exactly as the tool returned it. Never wrap a link in backticks or a code block: that renders it as inert text.
|
|
6
|
+
|
|
7
|
+
Be concise.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""The app's agent. The Agents SDK's CLI loads `agent` from here (`[tool.mistralai.agents]`).
|
|
2
|
+
|
|
3
|
+
mistral dev # serves it beside the app's other modules, under $AGENT_NAME
|
|
4
|
+
uv run agents chat . # chat with it in this process (from apps/agent)
|
|
5
|
+
mistral agents deploy # run it on the platform as a managed agent
|
|
6
|
+
|
|
7
|
+
Everything it can do comes from the files its installed capabilities contribute to this package:
|
|
8
|
+
`tools/`, `connectors/`, `hooks/`, `mcps/`, `subagents/`, `skills/` and `instructions/` (see
|
|
9
|
+
`mistralai_capabilities.agents.assembly`). `instructions.md` is the system prompt every composition
|
|
10
|
+
shares, so it names no capability's tools: tool-specific guidance belongs in the tool's description, or
|
|
11
|
+
in a capability's `instructions/<name>.md` fragment.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import mistralai.agents as agents
|
|
15
|
+
from env.agents import env as agent_env
|
|
16
|
+
from mistralai_capabilities.agents.assembly import assemble
|
|
17
|
+
|
|
18
|
+
import agent as package
|
|
19
|
+
|
|
20
|
+
# For a shell or Python, replace the files-only sandbox before spreading the fields (`environment=` beside
|
|
21
|
+
# `**assemble(package)` is a duplicate keyword):
|
|
22
|
+
# fields = assemble(package)
|
|
23
|
+
# fields["environment"] = agents.MistralSandbox(access="full")
|
|
24
|
+
# agent = agents.Agent(..., **fields)
|
|
25
|
+
agent = agents.Agent(
|
|
26
|
+
model=agent_env.agent_model,
|
|
27
|
+
name=agent_env.agent_name,
|
|
28
|
+
description="Answers with the tools, connectors and skills of the app's installed capabilities.",
|
|
29
|
+
**assemble(package),
|
|
30
|
+
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Remote MCP-server contributions merged into the app agent.
|
|
2
|
+
|
|
3
|
+
Each installed capability that contributes a remote HTTP MCP server vendors one ``<name>.py`` module
|
|
4
|
+
here exposing a single module-level ``mcp: agents.RemoteMCP`` (keyed by the module/file name -- one file per server);
|
|
5
|
+
``mistralai_capabilities.agents.assembly`` merges them into the app agent's fields.
|
|
6
|
+
See ``mistralai_capabilities.agents.assembly`` for the full contract.
|
|
7
|
+
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Skill contributions merged into the app agent: one `<name>/` folder per skill, holding its `SKILL.md` and any files it references. Each loads as an `agents.LocalSkillBundle`; when any is present the agent runs with a files-only sandbox (see `mistralai_capabilities.agents.assembly`). A `_`-prefixed folder is skipped.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Subagent contributions merged into the app agent.
|
|
2
|
+
|
|
3
|
+
Each installed capability that contributes a child agent vendors one ``<name>.py`` module here
|
|
4
|
+
exposing a single module-level ``subagent: agents.Subagent`` (one file per subagent, unique by
|
|
5
|
+
``Subagent.name``); the model spawns it through the SDK's built-in ``spawn`` tool. A module may set
|
|
6
|
+
``subagent = None`` to opt out. See ``mistralai_capabilities.agents.assembly`` for the full contract.
|
|
7
|
+
"""
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Tool contributions merged into the app agent.
|
|
2
|
+
|
|
3
|
+
Each installed capability that contributes a model-callable tool vendors one ``<tool>.py`` module
|
|
4
|
+
here exposing a single module-level ``tool: agents.PythonTool`` (an ``@agents.tool``) (one file per tool);
|
|
5
|
+
``mistralai_capabilities.agents.assembly`` merges them into the app agent's fields.
|
|
6
|
+
See ``mistralai_capabilities.agents.assembly`` for the full contract.
|
|
7
|
+
"""
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""The agent assembles and loads in this app, whatever capabilities are installed.
|
|
2
|
+
|
|
3
|
+
`assemble` fails loudly on a contribution that does not register (the agents toolkit's own tests pin
|
|
4
|
+
that), so loading the agent the way the SDK's CLI does is the check that the installed set assembles.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
from mistralai_capabilities.agents.assembly import assemble
|
|
15
|
+
from mistralai_capabilities.agents.hook_chain import handles_post_agent_turn
|
|
16
|
+
|
|
17
|
+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _probe(code: str, **env: str) -> str:
|
|
21
|
+
# A fresh interpreter: the agent is built at import time, so its settings must be set before it.
|
|
22
|
+
probe = subprocess.run(
|
|
23
|
+
[sys.executable, "-c", code], capture_output=True, text=True, check=True, env={**os.environ, **env}
|
|
24
|
+
)
|
|
25
|
+
return probe.stdout.strip()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_the_sdk_cli_loads_the_agent() -> None:
|
|
29
|
+
# `agents info` imports the `[tool.mistralai.agents]` entrypoint and runs the SDK's preflight
|
|
30
|
+
# checks, as `agents serve`, `agents run-worker` and `agents deploy` do before they start.
|
|
31
|
+
info = subprocess.run(
|
|
32
|
+
[str(Path(sys.executable).parent / "agents"), "info", str(PROJECT_ROOT)],
|
|
33
|
+
capture_output=True,
|
|
34
|
+
text=True,
|
|
35
|
+
env={**os.environ, "AGENT_NAME": "agent-info-test"},
|
|
36
|
+
)
|
|
37
|
+
assert info.returncode == 0, info.stdout + info.stderr
|
|
38
|
+
assert "agent-info-test" in info.stdout
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_name_and_model_come_from_the_environment() -> None:
|
|
42
|
+
printed = _probe(
|
|
43
|
+
"from agent.main import agent; print(agent.name, agent.model)",
|
|
44
|
+
AGENT_NAME="agent-env-test",
|
|
45
|
+
AGENT_MODEL="mistral-large-latest",
|
|
46
|
+
)
|
|
47
|
+
assert printed == "agent-env-test mistral-large-latest"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize(
|
|
51
|
+
("deployment", "expected"),
|
|
52
|
+
[
|
|
53
|
+
("shop-agent", "agent-shop"),
|
|
54
|
+
("-agent", "app-agent"),
|
|
55
|
+
("my.app-agent", "app-agent"),
|
|
56
|
+
(f"{'a' * 60}-agent", "app-agent"),
|
|
57
|
+
("deployment-shop-me", "app-agent"),
|
|
58
|
+
("", "app-agent"),
|
|
59
|
+
],
|
|
60
|
+
)
|
|
61
|
+
def test_a_deployed_agent_is_named_after_its_deployment(
|
|
62
|
+
monkeypatch: pytest.MonkeyPatch, deployment: str, expected: str
|
|
63
|
+
) -> None:
|
|
64
|
+
# `mistral dev` relies on AGENT_NAME from the app's `.env`, which wins; this pins the default.
|
|
65
|
+
from env.agents import Env
|
|
66
|
+
|
|
67
|
+
monkeypatch.delenv("AGENT_NAME", raising=False)
|
|
68
|
+
monkeypatch.setenv("DEPLOYMENT_NAME", deployment)
|
|
69
|
+
assert Env(_env_file=None).agent_name == expected
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_an_explicit_agent_name_wins_over_the_deployment(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
73
|
+
from env.agents import Env
|
|
74
|
+
|
|
75
|
+
monkeypatch.setenv("AGENT_NAME", "agent-custom")
|
|
76
|
+
monkeypatch.setenv("DEPLOYMENT_NAME", "shop-agent")
|
|
77
|
+
assert Env(_env_file=None).agent_name == "agent-custom"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@pytest.mark.parametrize(
|
|
81
|
+
("env", "expected"),
|
|
82
|
+
[
|
|
83
|
+
({"DEPLOYMENT_NAME": "shop-agent"}, "shop-worker"),
|
|
84
|
+
({"DEPLOYMENT_NAME": "shop-agent", "WORKFLOWS_DEPLOYMENT_NAME": "shop-batch"}, "shop-batch"),
|
|
85
|
+
({"DEPLOYMENT_NAME": "agent-shop"}, ""),
|
|
86
|
+
({}, ""),
|
|
87
|
+
],
|
|
88
|
+
)
|
|
89
|
+
def test_the_deployed_agent_starts_workflows_on_the_app_worker(env: dict[str, str], expected: str) -> None:
|
|
90
|
+
# Mistral Apps runs the image's CMD with only DEPLOYMENT_NAME, the agent's own `<app>-agent`, while
|
|
91
|
+
# the app's workflows run on its worker, `<app>-worker`: the CMD hands that to `start_workflow`.
|
|
92
|
+
dockerfile = PROJECT_ROOT.parents[1] / "deploy" / "docker" / "Dockerfile.agent"
|
|
93
|
+
# Relies on a single-line exec-form CMD whose setup ends at its last `exec `.
|
|
94
|
+
cmd = next(line for line in dockerfile.read_text().splitlines() if line.startswith("CMD "))
|
|
95
|
+
_shell, _flag, script = json.loads(cmd.removeprefix("CMD "))
|
|
96
|
+
setup, _, _ = script.rpartition("exec ")
|
|
97
|
+
probe = subprocess.run(
|
|
98
|
+
["sh", "-c", f'{setup}printf %s "${{WORKFLOWS_DEPLOYMENT_NAME:-}}"'],
|
|
99
|
+
capture_output=True,
|
|
100
|
+
text=True,
|
|
101
|
+
check=True,
|
|
102
|
+
env={"PATH": os.environ["PATH"], **env},
|
|
103
|
+
)
|
|
104
|
+
assert probe.stdout == expected
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_post_agent_turn_has_one_route() -> None:
|
|
108
|
+
# Several handlers would fold "last accept wins" on the original answer; assembly chains them.
|
|
109
|
+
import agent
|
|
110
|
+
|
|
111
|
+
assert sum(handles_post_agent_turn(hook) for hook in assemble(agent)["hooks"]) <= 1
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# syntax=docker/dockerfile:1
|
|
2
|
+
# The app's agent (apps/agent), built from the app root: it is a member of the app's uv workspace, so
|
|
3
|
+
# the contributions vendored into it import the app's packages from the same environment.
|
|
4
|
+
FROM python:3.14-slim AS build
|
|
5
|
+
COPY --from=ghcr.io/astral-sh/uv:0.13.7 /uv /uvx /bin/
|
|
6
|
+
RUN apt-get update && \
|
|
7
|
+
apt-get install -y --no-install-recommends build-essential && \
|
|
8
|
+
rm -rf /var/lib/apt/lists/*
|
|
9
|
+
WORKDIR /app
|
|
10
|
+
# uv bytecode-compiles each file under a 60 s default timeout, which a loaded build host can exceed;
|
|
11
|
+
# 900 s still fails a hung compile.
|
|
12
|
+
ENV UV_PYTHON_PREFERENCE=only-system \
|
|
13
|
+
UV_NO_PYTHON_DOWNLOADS=1 \
|
|
14
|
+
UV_LINK_MODE=copy \
|
|
15
|
+
UV_COMPILE_BYTECODE=1 \
|
|
16
|
+
UV_COMPILE_BYTECODE_TIMEOUT=900
|
|
17
|
+
# The build cannot reach a package mirror the developer locked through, so each sync first points
|
|
18
|
+
# the lock back at the public registries, again after `COPY . .` copies the original back.
|
|
19
|
+
COPY pyproject.toml uv.lock uv.tom[l] ./
|
|
20
|
+
COPY tools/uv.sh tools/normalise-lockfiles.sh tools/
|
|
21
|
+
RUN --mount=type=secret,id=registry_token \
|
|
22
|
+
--mount=type=secret,id=REGISTRY_TOKEN,env=REGISTRY_TOKEN \
|
|
23
|
+
--mount=type=cache,target=/root/.cache/uv \
|
|
24
|
+
bash tools/normalise-lockfiles.sh && \
|
|
25
|
+
bash tools/uv.sh sync --all-packages --frozen --no-dev --no-install-local
|
|
26
|
+
COPY . .
|
|
27
|
+
RUN --mount=type=secret,id=registry_token \
|
|
28
|
+
--mount=type=secret,id=REGISTRY_TOKEN,env=REGISTRY_TOKEN \
|
|
29
|
+
--mount=type=cache,target=/root/.cache/uv \
|
|
30
|
+
bash tools/normalise-lockfiles.sh && \
|
|
31
|
+
bash tools/uv.sh sync --all-packages --frozen --no-dev
|
|
32
|
+
|
|
33
|
+
FROM python:3.14-slim AS agent
|
|
34
|
+
COPY --from=ghcr.io/astral-sh/uv:0.13.7 /uv /uvx /bin/
|
|
35
|
+
WORKDIR /app
|
|
36
|
+
ENV UV_PYTHON_PREFERENCE=only-system \
|
|
37
|
+
UV_NO_PYTHON_DOWNLOADS=1 \
|
|
38
|
+
UV_CACHE_DIR=/tmp/uv-cache \
|
|
39
|
+
XDG_CACHE_HOME=/tmp \
|
|
40
|
+
PYTHONDONTWRITEBYTECODE=1 \
|
|
41
|
+
PATH="/app/.venv/bin:${PATH}"
|
|
42
|
+
# The agent's tools run in this process, so it needs the Debian packages the capabilities list for the
|
|
43
|
+
# worker (deploy/docker/worker-packages, present when the workflows capability is): the same tool code
|
|
44
|
+
# ran in the worker before. The script exits at once when no capability lists any.
|
|
45
|
+
RUN --mount=type=bind,source=deploy/docker,target=/tmp/docker \
|
|
46
|
+
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
|
|
47
|
+
if [ -f /tmp/docker/worker-packages/install.sh ]; then sh /tmp/docker/worker-packages/install.sh; fi
|
|
48
|
+
RUN groupadd -g 1000 app && \
|
|
49
|
+
useradd -u 1000 -g 1000 -m -s /usr/sbin/nologin app
|
|
50
|
+
COPY --from=build --chown=1000:1000 /app /app
|
|
51
|
+
USER 1000:1000
|
|
52
|
+
# `agents run-worker` serves the agent on the task queue registered for AGENT_NAME (or DEPLOYMENT_NAME
|
|
53
|
+
# when set) and registers nothing: it is what `mistral agents deploy` runs, after the deploy registered
|
|
54
|
+
# the agent. A deployment without the platform overrides it with `agents serve .`,
|
|
55
|
+
# which registers AGENT_NAME and then serves it.
|
|
56
|
+
# On Mistral Apps the platform names each module's deployment `<app>-<module>` and sets
|
|
57
|
+
# DEPLOYMENT_NAME to the agent's own, `<app>-agent`, and nothing else: WORKFLOWS_DEPLOYMENT_NAME,
|
|
58
|
+
# unless set, becomes the app's worker, `<app>-worker`, so a tool's `start_workflow` runs on the
|
|
59
|
+
# worker instead of the agent, which registers no workflow. env.agents derives the agent's default
|
|
60
|
+
# name from the same `<app>-agent`.
|
|
61
|
+
CMD ["sh", "-c", "case \"${DEPLOYMENT_NAME:-}\" in ?*-agent) export WORKFLOWS_DEPLOYMENT_NAME=\"${WORKFLOWS_DEPLOYMENT_NAME:-${DEPLOYMENT_NAME%-agent}-worker}\" ;; esac; exec uv run --frozen --no-dev --no-sync --directory apps/agent agents run-worker ."]
|
package/template/main.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""The app's agent, as the Agents SDK's CLI finds it from the app root.
|
|
2
|
+
|
|
3
|
+
The agent image builds from the root (`deploy/docker/Dockerfile.agent`), so the deploy runs there:
|
|
4
|
+
|
|
5
|
+
bash tools/uv.sh run --all-packages agents deploy . --dockerfile deploy/docker/Dockerfile.agent
|
|
6
|
+
|
|
7
|
+
The SDK loads `main:agent` from a project that declares no entrypoint, and the root `pyproject.toml`
|
|
8
|
+
declares none, so this module re-exports the agent defined in `apps/agent/src/agent/main.py`.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from agent.main import agent
|
|
12
|
+
|
|
13
|
+
__all__ = ["agent"]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Settings for the app's agent (`apps/agent`).
|
|
2
|
+
|
|
3
|
+
Its system prompt is ``agent/instructions.md`` followed by the ``agent/instructions/*.md`` fragments.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
from pydantic import Field
|
|
9
|
+
|
|
10
|
+
from env._base import BaseEnv
|
|
11
|
+
from env.app import deployed_app_name
|
|
12
|
+
|
|
13
|
+
# The control plane's agent name rule (the Agents SDK's AGENT_NAME_PATTERN): lowercase letters, digits
|
|
14
|
+
# and hyphens, a letter or digit at both ends, at most 63 characters. A `.` marks a platform agent.
|
|
15
|
+
_AGENT_NAME = re.compile(r"^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$")
|
|
16
|
+
_AGENT_NAME_MAX_LENGTH = 63
|
|
17
|
+
_FALLBACK_AGENT_NAME = "app-agent"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _default_agent_name() -> str:
|
|
21
|
+
# A deployed app agent runs as the workflows deployment `<app>-agent`, which sets only
|
|
22
|
+
# DEPLOYMENT_NAME: name it `agent-<app>` so each app in a workspace gets its own agent, unless
|
|
23
|
+
# the SDK would refuse that name. The Dockerfile.agent CMD derives the worker, `<app>-worker`, from
|
|
24
|
+
# the same name.
|
|
25
|
+
app = deployed_app_name()
|
|
26
|
+
if not app:
|
|
27
|
+
return _FALLBACK_AGENT_NAME
|
|
28
|
+
name = f"agent-{app}"
|
|
29
|
+
if len(name) > _AGENT_NAME_MAX_LENGTH or _AGENT_NAME.fullmatch(name) is None:
|
|
30
|
+
return _FALLBACK_AGENT_NAME
|
|
31
|
+
return name
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Env(BaseEnv):
|
|
35
|
+
# The name the agent is registered and served under: `mistral dev` serves it as this name, the
|
|
36
|
+
# agent image's worker resolves its task queue from it, and the app's other modules reach the
|
|
37
|
+
# agent by it. One name per deployment: the app's `.env` sets `AGENT_NAME` to `agent-<app>` (the
|
|
38
|
+
# capability's envVars), so this default only applies when nothing sets it. A deployment named
|
|
39
|
+
# `<app>-agent` defaults it to `agent-<app>`. The SDK refuses a name containing `.` (platform
|
|
40
|
+
# agents), so the default does not take the local user name.
|
|
41
|
+
agent_name: str = Field(default_factory=_default_agent_name)
|
|
42
|
+
|
|
43
|
+
# The model the agent runs on. A setting so a workspace that is rate-limited on the default can
|
|
44
|
+
# switch without editing the vendored `main.py`.
|
|
45
|
+
agent_model: str = "mistral-large-4"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
env = Env()
|
package/README.md
DELETED