agent-backend-development

A guide for adding or maintaining an Agent backend in Yuxi, the software that runs an Agent's code. It explains where backend files go and how Yuxi discovers them.

In plain words
What is it for?
Use it when building a new built-in Agent backend or changing an existing one, including its model, prompts, tools, Skills, approvals, summaries, usage tracking, or child agents.
Why use it?
It removes guesswork about the required files, class, and basic setup. It also separates backend code from configuration, permissions, and runtime context.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/xerrors/yuxi/agent-backend-development
Clone the repo
git clone --depth 1 https://github.com/xerrors/Yuxi
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,212 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01212
Opus 5 $0.00000 $0.00606
Sonnet 5 $0.00000 $0.00242
Haiku 4.5 $0.00000 $0.00121

Measured 2d ago against content hash d2ded4d987fc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

agent-backend-development scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/agents/agent-backend-development.md · 115 lines

How it starts

The opening of the file, as written. The whole thing — 115 lines — stays where its author put it; the contents beside it link to each section on GitHub.

开发智能体后端

本页面向需要在 Yuxi 中新增或维护 Agent 后端的贡献者。它只讲代码装配;配置字段、权限和运行时上下文分别见配置智能体Agent 运行时上下文

后端放在哪里

随服务发布的 Agent 后端放在:

backend/package/yuxi/agents/buildin/<your_agent>/
├── __init__.py
├── context.py
└── graph.py

buildin 包会遍历包含 __init__.py 的子目录,发现并注册其中的 BaseAgent 子类。__init__.py 需要导出该类。

最小实现

from langchain.agents import create_agent
from yuxi.agents import BaseAgent, BaseContext, load_chat_model
from yuxi.agents.context import prepare_agent_runtime_context


class MyAgent(BaseAgent):
    name = "我的智能体"
    description = "用于示例的智能体后端"
    context_schema = BaseContext

    async def get_graph(self, context=None, **kwargs):
        context = await prepare_agent_runtime_context(
            context or self.context_schema(),
            context_schema=self.context_schema,
        )
        return create_agent(
            model=load_chat_model(fully_specified_name=context.model),
            system_prompt=context.system_prompt,
            checkpointer=await self._get_checkpointer(),
        )

这个示例展示最小的 Context、模型、提示词和 PostgreSQL checkpoint 装配。真实后端还要根据需要接入文件 backend、工具、Skills、审批、Summary、用量和子智能体 middleware。

prepare_agent_runtime_context 会根据当前用户重新过滤资源,并在模型为空时补齐系统默认模型。不要在 get_graph() 中从浏览器输入、宿主机路径或数据库原始字段直接拼出可执行配置。

Context 和配置表单

需要让管理员或用户配置 Agent 行为时,在 context.py 扩展 BaseContext

from dataclasses import dataclass, field
from yuxi.agents import BaseContext


@dataclass(kw_only=True)
class MyAgentContext(BaseContext):
    response_style: str = field(
        default="concise",
        metadata={
            "name": "回答风格",
            "description": "控制回答的详细程度",
            "type": "string",
            "options": ["concise", "detailed"],
        },
    )

metadata 会影响 Agent 详情接口和 AgentRuntimeConfigForm。不要只在前端添加一个字段,也不要把运行期 ID、worker 身份和权限快照暴露成可保存配置。

新增字段后,沿下面的链路检查:

context_schema
  → get_configurable_items()
  → Agent 详情接口
  → 前端配置表单
  → config_json.context
  → get_graph(context)

Read the full file on GitHub · 115 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 115 lines · 0 tokens per session scan A d2ded4d987fc

Subscribe to this mod's changes

agent-backend-development is an agent published in the GitHub repository xerrors/Yuxi (6,591 stars, last pushed yesterday), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,212 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.