liveBook · Manning

Agent discovery

As explained in Context Engineering

The process by which a client agent retrieves another agent’s capabilities and connection parameters.

Agent discovery is the process by which a client agent retrieves another agent’s capabilities and connection parameters before delegating work. In Agent-to-Agent (A2A) communication, an agent card provides a JSON capability manifest that lets a client evaluate a potential collaborator programmatically. section 7.8.1

The client fetches the server’s agent card, selects an interface, and uses its connection details to send a task-oriented message. Discovery supplies capability and interface context; the subsequent message supplies the relevant task context. section 7.9.6 section 7.8.1

Discovering a weather agent

A Flask server exposes an agent-card.json file and a message endpoint. The client fetches the card, takes the first declared supported interface URL, and sends a weather request. The server returns a completed task-shaped response with a weather artifact. This is a teaching scaffold, not a conformant A2A implementation. section 7.9.6

Listing 7.8 A2A client logic for discovering a server agent and sending a message
agent_card_url = f"{SERVER_BASE_URL}/agent-card.json" #1
response = requests.get(agent_card_url)
response.raise_for_status()
agent_card = response.json()

interfaces = agent_card.get("supportedInterfaces", []) #2
if not interfaces:
    raise ValueError("Agent card does not declare a supported interface.")
message_endpoint = interfaces[0]["url"]

message_payload = { #3
    "message": {
        "messageId": str(uuid.uuid4()),
        "role": "ROLE_USER",
        "parts": [{"text": "Current weather. location: San Francisco, CA"}]
    },
    "configuration": {"acceptedOutputModes": ["text/plain"]}
}
headers = {"Content-Type": "application/a2a+json"}
message_response = requests.post(message_endpoint, json=message_payload,
headers=headers)
message_response.raise_for_status()
result_payload = message_response.json()

artifact = result_payload["task"]["artifacts"][0] #4
final_message = artifact["parts"][0]["text"]
print(f"Result: {final_message}")

Inspect the client’s card fetch, interface selection, and message submission. section 7.9.6

For production, use the protocol binding selected from the card, validate declared capabilities, and apply authentication. Handle task and context identifiers correctly and support the interaction mechanism required by the task. Consult the current A2A specification: the protocol continues to evolve. section 7.9.6 section 7.8.1

How Context Engineering covers it

How deep it goes
Demonstrates card retrieval and interface selection in a simplified client-server scaffold, while deferring full protocol conformance.
Examples
Uses a weather agent’s JSON card, Flask server, and client request to illustrate discovery and task submission.
What you can do after
Evaluate agent discovery by following a simplified card-fetching and message-submission flow.
How it connects
Connects agent discovery to agent cards, capability validation, task lifecycle management, and artifact exchange.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Context Engineering. The section links point to the parts of the book it draws on.