Skip to content

Commit

Permalink
edits: fixed conflicts and added missing code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixNicolaeBucsa committed Oct 17, 2024
1 parent e364a33 commit b7b7fb1
Show file tree
Hide file tree
Showing 13 changed files with 673 additions and 427 deletions.
6 changes: 6 additions & 0 deletions .github/spelling/known_words_corpus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,9 @@ etc
lifecycle
screenshot
docscode
richtext
bestmatches
gnews
newsrequest
v20
servicefordungeons
103 changes: 71 additions & 32 deletions pages/guides/agents/intermediate/mailbox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,54 +107,93 @@ Once the agent is correctly retrieved, you will have to give it a **name**. When

Let's update `alice` agent; `alice` will now print to console any message it receives, provided the message is of type `Message`. Remember that you need to provide the `AGENT_MAILBOX_KEY`, `SEED_PHRASE`, `name`, `seed` and `mailbox` parameters to correctly run this code:

```py copy filename="mailbox_agent_updated.py"
from uagents import Agent, Context, Model
<GithubCodeSegment digest="bb05019e1987c0454281a35446d404f4">
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/5-documentation/guides/agents/intermediate/mailbox/mailbox_agent_updated.py"
lineStart={1}
lineEnd={22}
hosted={true}
/>
</GithubCodeSegment>
<CodeGroup dynamic hasCopy isLocalHostedFile digest='bb05019e1987c0454281a35446d404f4'>

class Message(Model):
message: str
<DocsCode local={true}>
```py copy filename="mailbox_agent_updated.py"

AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"
SEED_PHRASE = "put_your_seed_phrase_here"
from uagents import Agent, Context, Model

class Message(Model):
message: str

AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"
SEED_PHRASE = "put_your_seed_phrase_here"

# Now your agent is ready to join the agentverse!
agent = Agent(
name="alice",
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
)

@agent.on_message(model=Message, replies={Message})
async def handle_message(ctx: Context, sender: str, msg: Message):
ctx.logger.info(f"Received message from {sender}: {msg.message}")


if __name__ == "__main__":
agent.run()

```
</DocsCode>

# Now your agent is ready to join the agentverse!
agent = Agent(
name="alice",
seed=SEED_PHRASE,
mailbox=f"{AGENT_MAILBOX_KEY}@https://agentverse.ai",
)
</CodeGroup>

@agent.on_message(model=Message, replies={Message})
async def handle_message(ctx: Context, sender: str, msg: Message):
ctx.logger.info(f"Received message from {sender}: {msg.message}")

if __name__ == "__main__":
agent.run()
```

## Creating a second agent

Let's create and run a second agent to message Alice every 3 seconds. You need to provide the `ALICE_ADDRESS`, `name` and `seed` parameters to correctly run this code:

```py copy filename="test_agent.py"

from uagents import Agent, Bureau, Context, Model
from datetime import datetime
<GithubCodeSegment digest="9c5f21c33a1c67291068668d85e62ce8">
<CodeSegment
path="https://github.com/fetchai/uAgent-Examples/blob/main/5-documentation/guides/agents/intermediate/mailbox/test_agent.py"
lineStart={1}
lineEnd={20}
hosted={true}
/>
</GithubCodeSegment>
<CodeGroup dynamic hasCopy isLocalHostedFile digest='9c5f21c33a1c67291068668d85e62ce8'>

class Message(Model):
message: str
<DocsCode local={true}>
```py copy filename="test_agent.py"

agent_2 = Agent(name="agent_2", seed="agent_2 recovery phrase", port=8001, endpoint="http://localhost:8001/submit")
from uagents import Agent, Bureau, Context, Model
from datetime import datetime


class Message(Model):
message: str


agent_2 = Agent(name="agent_2", seed="agent_2 recovery phrase", port=8001, endpoint="http://localhost:8001/submit")

ALICE_ADDRESS = "add_address_of_alice_agent"


@agent_2.on_interval(period=3.0)
async def send_message(ctx: Context):
await ctx.send(ALICE_ADDRESS, Message(message=f"hello {datetime.today().date()}"))


if __name__ == "__main__":
agent.run()

ALICE_ADDRESS = "add_address_of_alice_agent"
```
</DocsCode>

@agent_2.on_interval(period=3.0)
async def send_message(ctx: Context):
await ctx.send(ALICE_ADDRESS, Message(message=f"hello {datetime.today().date()}"))
</CodeGroup>

if __name__ == "__main__":
agent.run()

```

## Testing

Expand Down
3 changes: 2 additions & 1 deletion pages/guides/ai-engine-sdk/javascript.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Callout } from 'nextra/components'
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../components/code";
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../components/code";

# AI-Engine Javascript SDk

Expand Down Expand Up @@ -270,3 +270,4 @@ The following example demonstrates how to use the AI Engine SDK to interact with
</CodeGroup>



3 changes: 2 additions & 1 deletion pages/guides/ai-engine-sdk/python.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Callout } from 'nextra/components'
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../components/code";
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../components/code";

# AI-Engine Python SDk

Expand Down Expand Up @@ -323,3 +323,4 @@ The following example demonstrates how to use the AI Engine SDK to interact with
</CodeGroup>



2 changes: 1 addition & 1 deletion pages/guides/apis/agent-function-creation-apis.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../components/code";
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../components/code";

# Agents and Functions Creation using APIs

Expand Down
2 changes: 1 addition & 1 deletion pages/guides/apis/secret-management-apis.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Callout } from 'nextra/components'
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../components/code";
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../components/code";

# Adding Secret to Agents using Agentverse APIs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../components/code";
import { CodeGroup, CodeSegment, DocsCode, GithubCodeSegment } from "../../../../../components/code";

# Liquidity pool

Expand Down Expand Up @@ -435,3 +435,4 @@ The overall script should be as follows:
</CodeGroup>



Loading

0 comments on commit b7b7fb1

Please sign in to comment.