In the Hello World example, you used yield with AgentMessage to send textual data to the agent consumer. This concept has two important parts:
- Yielding data: You can yield data from your agent implementation, which gets sent to the client
- AgentMessage wrapper:
AgentMessage is a convenience wrapper around A2A Message that simplifies common use cases. Think of responding with text to the client.
Agent Stack SDK Message Types
The Agent Stack SDK simplifies development by allowing you to yield different types of data. You can use convenient SDK constructs or direct A2A components.
Convenience Wrappers
AgentMessage
The most common way to respond with text. It’s a convenience wrapper around A2A Message that makes it easy to create responses:
yield AgentMessage(text="This is my text", metadata={"foo": "bar"})
Plain strings
Simple strings are automatically converted to textual A2A Message objects:
Plain dict
Dictionaries sends Message containing DataPart
yield {"status": "processing", "progress": 50}
AgentArtifact
Same as AgentMessage but simplifies work with Artifacts.
Direct A2A Components
For more advanced use cases, you can yield direct A2A protocol components.
While it’s perfectly fine to yield plain A2A Components, the Agent Stack forms opinions on communication to support great UX in the GUI. For the best user experience, we recommend using the convenience wrappers when possible.
Feel free to check the A2A Key Concepts page to understand all the structures thoroughly.
Message
The basic communication unit in the A2A protocol, representing a single turn in a conversation.
import uuid
from a2a.types import Message, TextPart, Part, Role
# @server.agent(...)
async def example_agent():
yield Message(role=Role.agent, message_id=str(uuid.uuid4()), parts=[Part(root=TextPart(text="Hello from the agent!"))])
Part
The fundamental unit of content. For example, a TextPart contains text data. A Message consists of multiple Part objects. Can be any of TextPart, FilePart, or DataPart.
from a2a.types import TextPart
# @server.agent(...)
async def example_agent():
yield TextPart(text="Hello from the agent!")
Artifact
Tangible outputs produced by the agent, such as documents, files, or other generated content.
import uuid
from a2a.types import Artifact, FilePart, FileWithUri, Part
# @server.agent(...)
async def example_agent():
yield Artifact(
artifact_id=str(uuid.uuid4()),
parts=[Part(root=FilePart(file=FileWithUri(uri="https://www.ibm.com/us-en", mime_type="text/html", name="IBM Website")))],
)
TaskStatus
A stateful unit of work that can annotate a transaction spanning multiple messages. The task state can change over time as the agent progresses.
import uuid
from a2a.types import TaskStatus, TextPart, Message, TaskState, Part, Role
# @server.agent(...)
async def example_agent():
yield TaskStatus(
message=Message(message_id=str(uuid.uuid4()), role=Role.agent, parts=[Part(root=TextPart(text="Please provide some input."))]),
state=TaskState.input_required,
)