liveBook · Manning

Client agent

As explained in Context Engineering

The client agent is the example application’s agent that discovers the server agent and sends it a request.

A client agent packages task context and delegates work to a server agent on behalf of a user or parent workflow. In agent-to-agent (A2A) communication, it can discover a server’s capabilities from an agent card before sending a structured request. Client and server are interaction roles: the same agent can receive work as a server and delegate subtasks as a client. section 7.8.1

A simplified client-server flow has the client agent:

  • Fetch the server’s agent card and read its supported interfaces. section 7.9.6
  • Select an interface, construct a message with task context, and send it to the message endpoint. section 7.9.6
  • Receive a task-shaped response containing the result as an artifact. section 7.9.6

Weather request

A client fetches a local weather server’s agent card, takes the first supported interface, and posts a message requesting weather for San Francisco. The message includes a generated ID, a user role, a text part, and an accepted text output mode. The Flask server returns a completed task-shaped response with randomly generated weather, rather than a real forecast. 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 discovery, interface selection, and message submission logic. section 7.9.6

The example is a teaching scaffold, not a conformant A2A implementation. Production clients should use the protocol binding selected from the agent card, validate capabilities, authenticate, handle task and context identifiers correctly, and support the interaction mechanism required by the task. The protocol evolves, so consult the current specification before deployment. section 7.9.6 section 7.8.1

How Context Engineering covers it

How deep it goes
Shows discovery, interface selection, message submission, and a task-shaped response in code, while deferring full protocol conformance.
Examples
Uses a weather client and Flask server that exchange a location request and a randomly generated result.
What you can do after
Evaluate or understand a simplified A2A client flow and identify production requirements it leaves out.
How it connects
Connects A2A to agent cards, capability discovery, 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.