-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): examples flow updates (#1040)
Co-authored-by: Joshua Croft <[email protected]> Co-authored-by: Felix Nicolae Bucsa <[email protected]>
- Loading branch information
1 parent
6d56eb5
commit b7f06ab
Showing
15 changed files
with
173 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
{ | ||
"getting-started": { | ||
"title": "Getting Started" | ||
"easy": { | ||
"title": "Easy Topics" | ||
}, | ||
"intermediate": { | ||
"title": "Intermediate Topics" | ||
}, | ||
"advanced": { | ||
"title": "Advanced Topics" | ||
}, | ||
"jupyter-agent": "Jupyter Notebook Agent" | ||
"jupyter-agent": "Jupyter Notebook Agent", | ||
"hugging-face-agent": "Hugging Face Agent", | ||
"postgres-database-wigh-an-agent": "Postgres DB Integration", | ||
"react_example": "React web app Agent" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"first-agent": { | ||
"title": "Create your first agent", | ||
"tags": ["Agents", "Beginner", "Installation"], | ||
"timestamp": true | ||
}, | ||
"agents-interval-task": { | ||
"title": "Interval task with Agents", | ||
"tags": ["Intermediate", "Python", "Handlers", "Use Cases"], | ||
"timestamp": true | ||
}, | ||
"local-communication": { | ||
"title": "Local Network communication", | ||
"tags": ["Intermediate", "Python", "Communication", "Use Cases"], | ||
"timestamp": true | ||
}, | ||
"simple-agent-communication-with-bureau": { | ||
"title": "Bureau Agents communication", | ||
"tags": ["Intermediate", "Python", "Communication", "Use Cases"], | ||
"timestamp": true | ||
}, | ||
"storage": { | ||
"title": "Agents storage", | ||
"tags": ["Intermediate", "Python", "Storage", "Use Cases"], | ||
"timestamp": true | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...mples/intermediate/hugging-face-agent.mdx → pages/examples/hugging-face-agent.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...diate/postgres-database-with-an-agent.mdx → ...mples/postgres-database-with-an-agent.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/examples/intermediate/react_example.mdx → pages/examples/react-example.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Callout } from 'nextra/components' | ||
import { CodeGroup, DocsCode } from "../../../../components/code"; | ||
|
||
# Agents protocols | ||
|
||
Within the uAgents Framework, `protocols` support capturing related message types and handlers. | ||
|
||
Protocols are used to facilitate communication and interaction between agents in the Framework. | ||
|
||
<Callout type="info" emoji="ℹ️"> | ||
Indeed, any agent including the same protocol will be able to communicate with each other. | ||
</Callout> | ||
|
||
A `protocol` is built similar to an agent, but it has no identity and cannot be run. Protocols only contains the message types and handlers that define some components of an agent's functionality. | ||
|
||
Let's use a _simple restaurant table booking request_ as an example to better understand what a protocol means and how to build one: | ||
|
||
1. Let's start by creating a folder for our **protocols**. Then, let's create Python script within it, and name it: | ||
|
||
`mkdir protocols` | ||
|
||
and | ||
|
||
<CodeGroup hasCopy isOSFile> | ||
<DocsCode mac={true}> | ||
```py copy filename="mac" | ||
touch book.py | ||
``` | ||
</DocsCode> | ||
|
||
<DocsCode windows={true}> | ||
```py copy filename="windows" | ||
echo. > book.py | ||
``` | ||
</DocsCode> | ||
|
||
<DocsCode ubuntu={true}> | ||
```py copy filename="ubuntu" | ||
touch book.py | ||
``` | ||
</DocsCode> | ||
</CodeGroup> | ||
|
||
2. We import from `uagents` library the necessary classes `Context`, `Model`, and `Protocol`. Then, need to define the type of messages that the handler will receive and send: | ||
|
||
```py copy | ||
from uagents import Context, Model, Protocol | ||
|
||
class BookTableRequest(Model): | ||
table_number: int | ||
|
||
class BookTableResponse(Model): | ||
success: bool | ||
``` | ||
|
||
We use the `Model` class from `uagents` library to define `BookTableRequest` and `BookTableResponse` classes for setting up the structure of messages to be exchanged between your agents. The `BookTableRequest` class represents a request to book a table, containing the desired table number, while the `BookTableResponse` class represents the response to that request, indicating whether the booking was successful. | ||
|
||
3. Now, we would need to define the booking protocol as `book_proto` and also define the desired logic to determine if the `BookTableResponse` will be successful or not: | ||
|
||
```py copy | ||
book_proto = Protocol() | ||
|
||
@book_proto.on_message(model=BookTableRequest, replies={BookTableResponse}) | ||
async def handle_book_request(ctx: Context, sender: str, msg: BookTableRequest): | ||
if ctx.storage.has(str(msg.table_number)): | ||
success = False | ||
else: | ||
success = True | ||
ctx.storage.set(str(msg.table_number), sender) | ||
|
||
# send the response | ||
await ctx.send(sender, BookTableResponse(success=success)) | ||
``` | ||
|
||
4. We can then import our booking protocol from into the script we create for our agent, in the following way: | ||
|
||
```py copy | ||
from protocols.book import book_proto | ||
``` | ||
|
||
5. If your agent is called `restaurant` you can include the protocol in this way: | ||
|
||
```py copy | ||
restaurant.include(book_proto) | ||
``` | ||
|
||
For a better understanding of these concepts, consider having a look at the [Agents storage ↗️](/references/uagents/uagents-protocols/storage) and [Exchange protocol ↗️](/references/uagents/uagents-protocols/exchange-protocol) resources and consider going through the extensive [How to book a table at a restaurant using agents ↗️](/examples/table-booking-demo) guide in the [Agents guides ↗️](/guides#ai-agents) section. Also, checkout the [Agents: broadcast ↗️](/examples/broadcast) for an additional implementation of protocols in agents communication. |