fix: require current a2a init scaffold
All checks were successful
build / build (push) Successful in 26s
All checks were successful
build / build (push) Successful in 26s
This commit is contained in:
@@ -128,7 +128,7 @@ def build_tools(ctx: ToolContext) -> list[Any]:
|
||||
try:
|
||||
files = _render_a2a_init_template(name, description=description)
|
||||
prefix = _agent_prefix(name)
|
||||
except (OSError, ValueError) as exc:
|
||||
except (OSError, RuntimeError, ValueError) as exc:
|
||||
return json.dumps({"error": str(exc)})
|
||||
written: list[dict[str, Any]] = []
|
||||
for path, content in files.items():
|
||||
@@ -519,7 +519,7 @@ def _render_a2a_init_template(
|
||||
) -> dict[str, str]:
|
||||
_validate_name(name)
|
||||
class_name = _class_name(name)
|
||||
return {
|
||||
files = {
|
||||
"agent.py": _render_sdk_template(
|
||||
"agent.py.tmpl",
|
||||
name=name,
|
||||
@@ -533,6 +533,44 @@ def _render_a2a_init_template(
|
||||
),
|
||||
"requirements.txt": _render_sdk_template("requirements.txt.tmpl"),
|
||||
}
|
||||
_assert_current_a2a_init_template(files)
|
||||
return files
|
||||
|
||||
|
||||
def _assert_current_a2a_init_template(files: dict[str, str]) -> None:
|
||||
required_markers = {
|
||||
"agent.py": (
|
||||
"LLMProvisioning.CALLER_PROVIDED",
|
||||
"ctx.llm",
|
||||
"create_deep_agent",
|
||||
"wrap_model_call",
|
||||
"ChatOpenAI",
|
||||
),
|
||||
"requirements.txt": (
|
||||
"deepagents>=0.5.0",
|
||||
"langchain-openai",
|
||||
),
|
||||
}
|
||||
missing: list[str] = []
|
||||
for path, markers in required_markers.items():
|
||||
content = files.get(path, "")
|
||||
for marker in markers:
|
||||
if marker not in content:
|
||||
missing.append(f"{path}:{marker}")
|
||||
if not missing:
|
||||
return
|
||||
|
||||
try:
|
||||
import a2a_pack
|
||||
|
||||
version = getattr(a2a_pack, "__version__", "unknown")
|
||||
except Exception: # noqa: BLE001
|
||||
version = "unknown"
|
||||
raise RuntimeError(
|
||||
"installed a2a-pack init template is stale; expected the 0.1.3+ "
|
||||
"DeepAgents caller-LLM scaffold. "
|
||||
f"a2a_pack={version}; missing markers: {', '.join(missing)}"
|
||||
)
|
||||
|
||||
|
||||
def _render_sdk_template(template: str, /, **vars: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user