Skip to content

Agent Card Builder crashes if agent uses an InstructionProvider #6450

Description

@mattdarwin

Describe the Bug:
The LlmAgent​ parameter instruction (basically the prompt) can either be a string or an InstructionProvider​ , which is a callable that receives a ReadonlyContext and returns an instruction string (sync or async):
llm_agent.py: instruction: Union[str, InstructionProvider] = ''

However, if you create an Agent using an InstructionProvider, the A2A agent card builder fails, because it’s expecting a string not a function in agent.instruction​:

def _build_llm_agent_description_with_instructions(agent: LlmAgent) -> str:
....
    if agent.instruction:
        instruction = _replace_pronouns(agent.instruction)
...
def _replace_pronouns(text: str) -> str:
  ...
  return re.sub(
      pattern,
      lambda match: pronoun_map[match.group(1).lower()],
      text,  # <-- this parameter must be a string
      flags=re.IGNORECASE,
  )

Steps to Reproduce:

  1. Create an agent where the instruction parameter is an InstructionProvider (ie a function).
  2. Pass the agent into the build_card function in a2a.py

Expected Behavior:
The agent should build and run just fine.

Observed Behavior:
Stack trace inside the build_card call:

File ".venv/lib/python3.13/site-packages/google/adk/a2a/utils/agent_card_builder.py", line 74, in build
    primary_skills = await _build_primary_skills(self._agent)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/google/adk/a2a/utils/agent_card_builder.py", line 102, in _build_primary_skills
    return await _build_llm_agent_skills(agent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/google/adk/a2a/utils/agent_card_builder.py", line 112, in _build_llm_agent_skills
    agent_description = _build_llm_agent_description_with_instructions(agent)
  File ".venv/lib/python3.13/site-packages/google/adk/a2a/utils/agent_card_builder.py", line 339, in _build_llm_agent_description_with_instructions
    instruction = _replace_pronouns(agent.instruction)
  File ".venv/lib/python3.13/site-packages/google/adk/a2a/utils/agent_card_builder.py", line 377, in _replace_pronouns
    return re.sub(
           ~~~~~~^
        pattern,
        ^^^^^^^^
    ...<2 lines>...
        flags=re.IGNORECASE,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File ".venv/lib/python3.13/re/__init__.py", line 208, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'function'

Environment Details:

  • ADK Library Version (pip show google-adk): 1.33.0
  • Desktop OS: MacOs
  • Python Version (python -V): 3.13

Model Information:

  • Are you using LiteLLM:No
  • Which model is being used: claude-opus-4.6, but it happens for any model

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression:
Did this work in a previous version of ADK?
Don't know

Logs:
Please attach relevant logs. Wrap them in code blocks (```) or attach a
text file.

// Paste logs here

Screenshots / Video:
If applicable, add screenshots or screen recordings to help explain
your problem.

Additional Context:
Add any other context about the problem here.

Minimal Reproduction Code:
Please provide a code snippet or a link to a Gist/repo that isolates the issue.

// Code snippet here

How often has this issue occurred?:

  • Always (100%)

Metadata

Metadata

Assignees

Labels

a2a[Component] This issue is related a2a support inside ADK.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions