agent_card.go

Overview

The agent_card.go file is responsible for generating descriptive skill metadata about agents in the system. It builds a list of a2a.AgentSkill objects that summarize an agent's capabilities, including its core model or workflow type, integrated tools, and sub-agent compositions. This metadata is used in the Agent-To-Agent (A2A) protocol's AgentCard to inform clients about what an agent can do, facilitating discovery, orchestration, and delegation in distributed multi-agent systems.

The file covers:

These capabilities help remote clients understand agent features before invoking them and support detailed agent capability advertisements.


Classes and Functions

BuildAgentSkills(agent.Agent) []a2a.AgentSkill

Purpose:
Entry point function that builds a comprehensive list of a2a.AgentSkill descriptors for a given agent. It combines primary skills with recursively collected sub-agent skills.

Parameters:

Returns:

Usage Example:

skills := BuildAgentSkills(myAgent)
for _, skill := range skills {
    fmt.Println(skill.Name, ":", skill.Description)
}

buildPrimarySkills(agent.Agent) []a2a.AgentSkill

Purpose:
Determines whether the agent is an LLM-based agent or not and delegates to the appropriate skill building function.

Parameters:

Returns:


buildSubAgentSkills(agent.Agent) []a2a.AgentSkill

Purpose:
Recursively builds skills for all sub-agents of the given agent. Each sub-agent skill is prefixed with the sub-agent's name and tagged as a sub-agent skill.

Parameters:

Returns:


buildLLMAgentSkills(agent.Agent, *llminternal.State) []a2a.AgentSkill

Purpose:
Constructs skill descriptors for LLM-based agents. It includes:

Parameters:

Returns:


buildNonLLMAgentSkills(agent.Agent) []a2a.AgentSkill

Purpose:
Builds skills for non-LLM agents such as workflow agents and custom agents. It also describes orchestration when sub-agents are present.

Parameters:

Returns:


buildAgentDescription(agent.Agent, *iagent.State) string

Purpose:
Generates a natural language description of the agent, factoring in:

Parameters:

Returns:


buildSequentialAgentDescription(agent.Agent) string

Purpose:
Creates a narrative description for sequential workflow agents by enumerating sub-agents in execution order (first, then, finally).


buildParallelAgentDescription(agent.Agent) string

Purpose:
Creates a natural language description for parallel workflow agents, describing concurrent execution of sub-agents.


buildLoopAgentDescription(agent.Agent, *iagent.State) string

Purpose:
Generates a description for loop workflow agents, including the maximum number of iterations and sub-agent execution details.


buildDescriptionFromInstructions(agent.Agent, *llminternal.State) string

Purpose:
Builds descriptions for LLM agents from instructions and global instructions, replacing pronouns to convert second-person instructions into first-person perspective for clarity.


replacePronouns(string) string

Purpose:
Replaces second-person pronouns and verb conjugations in instructions to first-person equivalents to improve agent self-descriptions.

Example:


getDefaultAgentDescription(*iagent.State) string

Purpose:
Returns a default description string based on the internal agent type if no custom descriptions are available.


getAgentTypeTag(*iagent.State) string

Purpose:
Returns a string tag identifying the agent type, such as "llm_agent" or "sequential_workflow", used for skill tagging.


getAgentSkillName(*iagent.State) string

Purpose:
Determines the skill name used for the primary agent skill, typically "model" for LLM agents or "workflow" for workflow agents.


getInternalState(agent.Agent) *iagent.State

Purpose:
Extracts the internal agent state from an agent.Agent interface if it implements the internal agent interface. Otherwise, returns a default custom agent state.


isWorkflowAgent(*iagent.State) bool

Purpose:
Checks if the agent type corresponds to a workflow agent type (loop, sequential, or parallel).


Important Implementation Details and Algorithms


Interaction with Other System Components


Diagram: Agent Skill Building Structure

flowchart TD
Agent[Agent Instance]
BuildSkills(BuildAgentSkills)
PrimarySkills[buildPrimarySkills]
SubAgentSkills[buildSubAgentSkills]
LLMSkills[buildLLMAgentSkills]
NonLLMSkills[buildNonLLMAgentSkills]
SkillList[""["] a2a.AgentSkill"]
Agent --> BuildSkills
BuildSkills --> PrimarySkills
BuildSkills --> SubAgentSkills
PrimarySkills -->|LLM Agent| LLMSkills
PrimarySkills -->|Non-LLM Agent| NonLLMSkills
LLMSkills --> SkillList
NonLLMSkills --> SkillList
SubAgentSkills --> SkillList

This flowchart illustrates the sequence of steps starting from an agent instance, where primary skills are built based on agent type, sub-agent skills are recursively collected, and all are combined into the final list of a2a.AgentSkill objects.


References to Relevant Topics


This documentation details the mechanisms for generating agent skill descriptions that enable comprehensive capability advertisement in distributed multi-agent systems.