AGENT SKILL
MAF 智能体框架搭建
maf-agent-skeleton
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-29
- Stars
- ★ 10
- Forks
- 31
03 SKILL.md 正文
Skill: MAF Agent Skeleton
Use this skill when generating any specialist agent under src/agents/<name>/.
Reference layout
src/agents/<name>/
├── __init__.py
├── prompts.py
├── tools.py
├── agent.py
├── server.py
├── Dockerfile
└── tests/__init__.py
agent.py template (specialist with MCP)
from __future__ import annotations
from dataclasses import dataclass
from agent_framework import AgentResponse
from agent_framework.github import GitHubCopilotAgent, GitHubCopilotOptions
from copilot.generated.rpc import PermissionDecisionApproveOnce
from copilot.session import PermissionRequestResult
from src.shared.copilot import build_copilot_client
from src.shared.settings import Settings
from .prompts import SYSTEM_PROMPT
from .tools import TOOLS # usually empty: list[FunctionTool] = []
def _approve_all(_req: object, _ctx: dict[str, str]) -> PermissionRequestResult:
return PermissionDecisionApproveOnce()
@dataclass(frozen=True)
class _RunnableAgent:
"""Adapter satisfying the shared `make_app` `_Runnable` protocol."""
agent: GitHubCopilotAgent
async def run(self, message: str, /) -> AgentResponse[None]:
return await self.agent.run(message)
async def build_agent(settings: Settings) -> _RunnableAgent:
agent = GitHubCopilotAgent(
instructions=SYSTEM_PROMPT,
client=build_copilot_client(),
name="<name>",
description="ZavaShop <name> specialist (...).",
tools=list(TOOLS),
default_options=GitHubCopilotOptions(
model=settings.copilot_model,
timeout=settings.copilot_timeout_seconds,
on_permission_request=_approve_all,
mcp_servers={
"<key>": {
"type": "http",
"url": settings.<which>_mcp_url,
"tools": ["*"],
"timeout": int(settings.copilot_timeout_seconds * 1000),
},
},
),
)
return _RunnableAgent(agent=agent)
Rules:
- One
build_agentper agent. Async. Returns the_RunnableAgentadapter —make_apponly needs.run(message). - Settings is the only configuration source. No env reads inside
agent.py. GitHubCopilotAgent+GitHubCopilotOptionsis the only allowed chat surface. NoGitHubCopilotChatClient, noChatAgent(client=...), noMCPStreamableHTTPTool— those do not exist in agent-framework 1.3.x.client=build_copilot_client()is mandatory soGITHUB_TOKENis honored in local, AKS, and ACA runtimes.on_permission_request=_approve_allreturningPermissionDecisionApproveOnce()is mandatory; without it every tool call silently denies and the LLM hallucinates "all specialists rejected".mcp_servers[*].timeoutis milliseconds; useint(settings.copilot_timeout_seconds * 1000).- For the orchestrator (no MCP), drop
mcp_serversand put four@tool-decoratedasync def ask_<peer>(goal: str)functions inagent.pyitself, each callingA2AClient.invoke(...). Tool signatures must be flat scalars, never Pydantic models (the SDK passes a raw dict).
prompts.py template
SYSTEM_PROMPT = """\
You are <Name>Agent for ZavaShop. Role: <one sentence>.
Decision rules:
1. ...
2. ...
Refusal rules:
- Refuse <out-of-scope topic>; redirect to the right agent.
- Never invent SKUs, prices, or supplier names.
Output: a JSON object with keys {...}.
"""
server.py template
from src.shared.server import make_app
from .agent import build_agent
app = make_app(name="<name>", build=build_agent)
No business logic in server.py. Ever.
tools.py rules
- Specialist agents normally export
TOOLS: list[FunctionTool] = []— external I/O lives in their MCP server, not intools.py. - If a tool is defined locally (orchestrator's
ask_*delegators), use@toolfromagent_framework. Signature must be flat scalars (goal: str), not a Pydantic input — the Copilot SDK does not marshal dicts into models. - Docstring must include a one-line summary,
Args:,Returns:. - Export the
TOOLSlist at the bottom —agent.pyconsumes it.
Acceptance
uv run ruff check src/agents/<name>
uv run pyright src/agents/<name>
uv run python -c "from src.agents.<name>.agent import build_agent; print(build_agent)"
04 同仓库更多 Skills
Pydantic 数据契约验证
pydantic-contracts
暂无简介
★ 10
MCP 服务端框架搭建
mcp-server-skeleton
暂无简介
★ 10
Copilot SDK GPT-5.5 集成
copilot-sdk-gpt55
暂无简介
★ 10
AKS Helm 应用部署
aks-helm
暂无简介
★ 10
ACA Bicep 部署模板
aca-bicep
暂无简介
★ 10
A2A 回环测试
a2a-loopback-tests
暂无简介
★ 10