Skip to content

Commit

Permalink
feat(docs): add Agent Envelopes guide in Agents Advanced Guides (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNicolaeBucsa authored Aug 9, 2024
1 parent 82a5c24 commit 5b03894
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pages/guides/agents/advanced/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"title": "Almanac Contract",
"tags": ["Agents", "AI", "Almanac", "Registration", "Advanced"]
},
"agent-envelopes": {
"title": "Agent Envelopes",
"tags": ["Agents", "AI", "Envelopes", "ExchangeProtocol", "Communication"]
},
"message-verification": {
"title": "Verify messages with Agents",
"tags": ["Agents", "AI", "Communication", "Advanced"]
Expand Down
56 changes: 56 additions & 0 deletions pages/guides/agents/advanced/agent-envelopes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Callout } from 'nextra/components'

# Agent Envelopes in the Fetch.ai uAgents Framework

## Introduction

Within the Fetch.ai uAgents Framework, effective communication between [Agents ↗️](/guides/agents/getting-started/whats-an-agent) is crucial for the execution of complex tasks and exchange of information. To this aim, the **Exchange protocol** is a standardized communication protocol within the Framework that facilitates such interactions. A key component of this protocol are **Envelopes**; these serve as structured containers for messages exchanged between agents.

In particular, envelopes provide a secure and reliable way to exchange messages by encapsulating them along with essential metadata. This metadata includes details about the sender and recipient, the session in which the communication occurs, and other information needed to ensure the integrity and authenticity of the messages. By using envelopes, we ensure that messages are correctly routed, verified, and processed, thereby enabling straightforward interoperability among multiple agents and related functions.

<Callout type="info" emoji="ℹ️">
Checkout the [Exchange protocol ↗️](/references/uagents/uagents-protocols/exchange-protocol) resource for a better comprehension on this topic.
</Callout>

## What Are Envelopes?

**Envelopes** are specialized structures used to encapsulate messages in the Exchange protocol. The structure of an envelope can be likened to a physical envelope containing a letter, where the outer envelope holds information such as the sender's and recipient's addresses, while the inner letter (i.e., the payload) carries the actual content.

They play a critical role in the communication process by:

1. **Packaging the message**: Envelopes contain the message payload, ensuring that all necessary information is transmitted together.
2. **Providing metadata**: Envelopes include metadata such as sender and recipient addresses, session information, and expiration times. This metadata helps in identifying and routing the message correctly.
3. **Ensuring security and integrity**: Envelopes can include digital signatures and other security features to authenticate the sender and ensure the message has not been tampered with.

## Structure of an Envelope

The `Envelope` class can be defined as follows:

```py
@dataclass
class Envelope(BaseModel):
version: int # Envelope version
sender: str: # Bech32-encoded public address of the sender
target: str: # Bech32-encoded public address of the target recipient
session: UUID4 # UUID of the session
schema_digest: str # Digest of the schema used for the payload
protocol_digest: Optional[str] # Optional protocol digest for custom protocols
payload: Optional[str] # JSON payload encoded as a base64 string
expires: Optional[int] # Unix timestamp in seconds indicating expiration
nonce: Optional[int] # Optional nonce
signature: Optional[str] # Bech32-encoded signature
```

<Callout type="info" emoji="ℹ️">
Envelopes are quite similar to **blockchain transactions**.
</Callout>

## Sending Envelopes

Envelopes are encoded in JSON format and sent via `HTTP 1.1 POST` requests to specific endpoints of receiving agents or services. Currently, the protocol supports only one standardized endpoint:

`HTTP 1.1 POST /submit`

This endpoint expects data that adheres to a JSON-compatible format, typically using the MIME content type `application/json`.

**In essence, Envelopes in the uAgents Framework act as secure wrappers for messages, providing essential information for their secure and reliable transmission between Agents within the Framework itself.**
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Exchange protocol enables agents to exchange **messages** using a **JSON-bas

Within the protocol, **envelopes** facilitate communication by encapsulating messages. Envelopes serve as containers for the messages and include additional metadata.

In this protocol, gents can send **messages** enclosed in **envelopes**, which are then encoded and sent via HTTP to the [endpoints ↗️](/references/contracts/uagents-almanac/endpoints) of other agents.
In this protocol, agents can send **messages** enclosed in **envelopes**, which are then encoded and sent via HTTP to the [endpoints ↗️](/references/contracts/uagents-almanac/endpoints) of other agents.

By adhering to the agents Exchange Protocol, agents within the Fetch.ai uAgents ecosystem can communicate with each other using a standardized and interoperable method.

Expand Down

0 comments on commit 5b03894

Please sign in to comment.