# Agent-to-agent communication

Canonical URL: https://agentlearn.dev/learn/agents/a2a
Author: [Hemanth HM](https://h3manth.com)
Track: agents
Reading time: 10 minutes

When work crosses agent-system boundaries, explicit tasks and artifacts are more dependable than an informal chat transcript.

## Delegate work, not unlimited authority

A support system might ask a separate logistics system for a delivery investigation. A2A defines structures for communicating capabilities, messages, tasks, and artifacts across systems. It does not ensure that a remote agent is correct, trustworthy, or authorized to act on behalf of a customer.

## How it works

Define the task's expected output and lifecycle: submitted, working, input required, completed, or failed, using the exact states of your chosen protocol version. Track a correlation identifier, deadlines, cancellation, and duplicate submissions. Validate the returned artifact against your contract before using it in a customer response.

## A concrete example

A logistics agent returns an estimated arrival date plus the carrier reference used. If it instead asks for a missing tracking number, the support assistant should collect that information rather than treating the task as completed. Completion status and artifact quality are different checks.

## Apply it to your assistant

Remove the carrierReference and observe validation fail. Before running the exercise, predict the result. Afterward, explain which assumption changed and add one case where the system should refuse, ask for clarification, or escalate.

All exercise inputs and outputs are deterministic teaching examples. No language model is called. Run the same idea against a versioned dataset before making a production claim.


## Key takeaway

Cross-system delegation needs identity, lifecycle management, and artifact validation.

## JavaScript exercise: Agent-to-agent communication · code experiment

Remove the carrierReference and observe validation fail.

```javascript
const task = { id: 'investigation-1', state: 'completed', artifact: { arrival: 'Friday', carrierReference: 'tracking-42' } };
const valid = task.state === 'completed' && typeof task.artifact?.carrierReference === 'string';
console.log({ taskId: task.id, accepted: valid });
console.log('Simplified application contract, not an A2A wire message.');
```

## Knowledge check

A remote task says completed but returns no required evidence. What should the caller do?

1. Trust the status field alone
2. Mark the artifact invalid and handle the contract failure
3. Invent the missing evidence

Answer: Mark the artifact invalid and handle the contract failure

A completed lifecycle state is not proof that the returned artifact satisfies the caller's acceptance criteria.

## Sources

- [Agent2Agent Protocol specification](https://a2a-protocol.org/latest/specification/) — A2A contributors, Living specification. Discovery, messages, tasks, artifacts, and interoperability between agent systems.
