|
27 | 27 |
|
28 | 28 | import io |
29 | 29 | import os |
| 30 | +import re |
30 | 31 | import shutil |
31 | 32 | import tempfile |
32 | 33 | import zipfile |
|
66 | 67 | "HarnessConfig", |
67 | 68 | "HarnessOverrides", |
68 | 69 | "split_csv", |
| 70 | + "agent_name_from_harness", |
69 | 71 | "build_skill_toolset", |
70 | 72 | "SkillLoadError", |
71 | 73 | "ToolLoadError", |
@@ -111,6 +113,7 @@ def _load_builtin_tool(name: str) -> Any: |
111 | 113 | "tools": "TOOLS", |
112 | 114 | "skills": "SKILLS", |
113 | 115 | "system_prompt": "SYSTEM_PROMPT", |
| 116 | + "description": "DESCRIPTION", |
114 | 117 | "runtime": "RUNTIME", |
115 | 118 | "structured_tool_calls": "STRUCTURED_TOOL_CALLS", |
116 | 119 | "include_tools_every_turn": "INCLUDE_TOOLS_EVERY_TURN", |
@@ -139,6 +142,24 @@ def split_csv(value: str) -> list[str]: |
139 | 142 | return [item.strip() for item in value.split(",") if item.strip()] |
140 | 143 |
|
141 | 144 |
|
| 145 | +def agent_name_from_harness(harness_name: str) -> str: |
| 146 | + """Derive a valid ADK agent name from the harness name. |
| 147 | +
|
| 148 | + The agent name becomes the A2A agent card's ``name``, so it should reflect |
| 149 | + the harness rather than a shared constant. ADK requires the agent ``name`` |
| 150 | + to be a Python identifier (letters, digits, underscores; not starting with a |
| 151 | + digit) and forbids ``"user"``, while harness names also allow ``-`` and may |
| 152 | + start with a digit. Normalize: map every non-identifier char to ``_`` and |
| 153 | + prefix a digit-leading or empty name with ``_``. |
| 154 | +
|
| 155 | + ``"oauth-test"`` -> ``"oauth_test"``; ``"2048-bot"`` -> ``"_2048_bot"``. |
| 156 | + """ |
| 157 | + name = re.sub(r"[^0-9A-Za-z_]", "_", harness_name or "") |
| 158 | + if not name or name[0].isdigit(): |
| 159 | + name = f"_{name}" |
| 160 | + return f"{name}_" if name == "user" else name |
| 161 | + |
| 162 | + |
142 | 163 | def _download_and_extract_skill(skill: str, dest_dir: Path) -> Path: |
143 | 164 | """Download a skill zip from the skill hub and extract it. |
144 | 165 |
|
@@ -315,9 +336,10 @@ def _assemble_agent(config: HarnessConfig) -> tuple[Agent, ShortTermMemory]: |
315 | 336 | ) |
316 | 337 |
|
317 | 338 | agent = Agent( |
318 | | - name="harness_agent", |
| 339 | + name=agent_name_from_harness(config.app_name), |
319 | 340 | model_name=config.model_name, |
320 | 341 | instruction=config.system_prompt, |
| 342 | + description=config.description, |
321 | 343 | tools=tools, |
322 | 344 | runtime=config.runtime, |
323 | 345 | enable_responses=config.structured_tool_calls, |
|
0 commit comments