Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): add guide for chat protocol #1109

Merged
merged 14 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pages/guides/agents/intermediate/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@
"title": "Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline",
"tags": ["Intermediate", "Python", "Functions", "AI Engine", "Local"],
"timestamp": true
},
"chat-protocol": {
"title": "Chat protocol",
"tags": ["Intermediate", "Python", "protocols", "fetch.ai SDK"],
"timestamp": true
}
}
55 changes: 55 additions & 0 deletions pages/guides/agents/intermediate/chat-protocol.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Agent Chat Protocol

**Agents must strictly adhere to the chat protocol to enable seamless and consistent communication**. The chat protocol expects all message payloads to follow a structured yet flexible `{any: any}` format, where both keys and values can dynamically adapt to the context of the message.

## Key Points

- **Dynamic Payload**: The payload can follow the format `{any: any}`, ensuring flexibility in data exchange.

- **Message Structure**: Every message sent or received must conform to this structure, enabling seamless communication between Agents.

- **Example Usage**:

Searching for Agents and sending a message:

```py copy
payload = {"any": "any"}

send_message_to_agent(
gautamgambhir97 marked this conversation as resolved.
Show resolved Hide resolved
sender=sender_identity,
target=ai.get("address", ""),
payload=payload,
session=uuid4()
)
```

- **Protocol Enforcement**:

Always ensure the message payload and responses align with `{any: any}` to maintain compatibility.

### When the payload in a message changes, two key things happen behind the scene

- **Payload Encoding**:

The payload, typically a JSON object, is first serialized into a string and then encoded using a method like Base64. Any change to the payload—whether it's altering a value, adding a key, or removing an entry—results in a completely different encoded string.

- **Signature Generation**:

The signature is a cryptographic hash that verifies the integrity of the message. It is generated based on the encoded payload along with other fields such as the sender, target, session, and protocol digest. When the encoded payload changes, the signature must also change to reflect the updated data.

This protocol standard simplifies Agents communication while allowing for diverse use cases without predefined schemas.

```py
{
"version": 1,
"sender": "agent1qdtxzn2e0dg8y2v5y53p7frplt4w6wq36rfapv38g8x9ukgpc28fgfqnjug",
"target": "agent1qw7802t7qf98kg775k7f5v3f9h864c72eja2r94pumxnvyx3492xyzu8fmg",
"session": "2d744b6e-ad94-4397-ab56-8e2b6dd776e7",
"schema_digest": "model:708d789bb90924328daa69a47f7a8f3483980f16a1142c24b12972a2e4174bc6",
"protocol_digest": "proto:a03398ea81d7aaaf67e72940937676eae0d019f8e1d8b5efbadfef9fd2e98bb2",
"payload": "eyJhc2Rhc3Nzc3Nzc3Nzc3MiOiJhd3dkYXNkYWQifQ==",
"expires": null,
"nonce": null,
"signature": "sig13gcpvxhfytgzpu66xf8kfhnzx56pk2wmulfrplthjfqep4m5y6u77pq83c9934qsed4xucdjkhzw3n8490xqt75jnpmf939mkmkdgwqnngly4"
}
```
Loading