Skip to content

Commit

Permalink
chore: merge main and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Jul 12, 2023
2 parents 465363e + efa2113 commit 6c96a94
Show file tree
Hide file tree
Showing 24 changed files with 561 additions and 203 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ disable=missing-module-docstring,
too-many-arguments,
logging-fstring-interpolation,
import-outside-toplevel,
too-many-statements
too-many-statements,
too-many-locals

22 changes: 14 additions & 8 deletions docs/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ Envelopes have the following form and are quite similar to blockchain transactio
```python
@dataclass
class Envelope:
sender: str: # bech32-encoded public address
target: str: # bech32-encoded public address
session: str # UUID
protocol: str # protocol digest
payload: bytes # JSON type: base64 str
expires: int # Unix timestamp in seconds
signature: str # bech32-encoded signature
sender: str: # bech32-encoded public address
target: str: # bech32-encoded public address
session: str # UUID
schema_digest: str # digest of message schema used for routing
protocol_digest: str # digest of protocol containing message
payload: bytes # JSON type: base64 str
expires: int # Unix timestamp in seconds
nonce: int # unique message nonce
signature: str # bech32-encoded signature
```

### Semantics
Expand All @@ -47,12 +49,16 @@ The **sender** field exposes the address of the sender of the message.

The **target** field exposes the address of the recipient of the message.

The **protocol** contains the unique schema digest string for the message.
The **schema_digest** contains the unique schema digest string for the message.

The **protocol_digest** contains the unique digest for protocol containing the message if available.

The **payload** field exposes the payload of the protocol. Its JSON representation should be a base64 encoded string.

The **expires** field contains the Unix timestamp in seconds at which the message is no longer valid.

The **nonce** is a sequential number used to ensure each message is unique.

The **signature** field contains the signature that is used to authenticate that the message has been sent from the **sender** agent.

Envelopes are then JSON encoded and sent to endpoints of other agents or services.
Expand Down
11 changes: 9 additions & 2 deletions examples/08-local-network-interaction/agent1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from uagents.setup import fund_agent_if_low
from uagents.resolver import get_agent_address
from uagents import Agent, Context, Model


Expand All @@ -10,15 +11,21 @@ class Message(Model):


bob = Agent(
name="bob",
name="agent bob",
port=8001,
seed="bob secret phrase",
seed="agent bob secret phrase",
endpoint=["http://127.0.0.1:8001/submit"],
)

fund_agent_if_low(bob.wallet.address())


@bob.on_event("startup")
async def register_name(ctx: Context):
await bob.register_name()
print("agent bob registered address: ", get_agent_address(ctx.name))


@bob.on_message(model=Message)
async def message_handler(ctx: Context, sender: str, msg: Message):
ctx.logger.info(f"Received message from {sender}: {msg.message}")
Expand Down
4 changes: 1 addition & 3 deletions examples/08-local-network-interaction/agent2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class Message(Model):
message: str


RECIPIENT_ADDRESS = "agent1q2kxet3vh0scsf0sm7y2erzz33cve6tv5uk63x64upw5g68kr0chkv7hw50"

alice = Agent(
name="alice",
port=8000,
Expand All @@ -20,7 +18,7 @@ class Message(Model):

@alice.on_interval(period=2.0)
async def send_message(ctx: Context):
await ctx.send(RECIPIENT_ADDRESS, Message(message="Hello there bob."))
await ctx.send("agent bob", Message(message="Hello there bob."))


@alice.on_message(model=Message)
Expand Down
16 changes: 10 additions & 6 deletions examples/09-booking-protocol-demo/query.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import asyncio

from protocols.query import GetTotalQueries
from protocols.query import GetTotalQueries, TotalQueries

from uagents.contrib.protocols.protocol_query import ProtocolQuery, ProtocolResponse
from uagents.query import query


RESTAURANT_ADDRESS = "agent1qw50wcs4nd723ya9j8mwxglnhs2kzzhh0et0yl34vr75hualsyqvqdzl990"

get_total_queries = GetTotalQueries()
RESTAURANT_ADDRESS = "agent1qfpqn9jhvp9cg33f27q6jvmuv52dgyg9rfuu37rmxrletlqe7lewwjed5gy"


async def main():
env = await query(RESTAURANT_ADDRESS, get_total_queries)
print(f"Query response: {env.decode_payload()}")
env = await query(RESTAURANT_ADDRESS, GetTotalQueries())
msg = TotalQueries.parse_raw(env.decode_payload())
print(f"Query response: {msg.json()}\n\n")

env = await query(RESTAURANT_ADDRESS, ProtocolQuery())
msg = ProtocolResponse.parse_raw(env.decode_payload())
print("Protocol query response:", msg.json(indent=4))


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions examples/09-booking-protocol-demo/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from protocols.query import query_proto, TableStatus

from uagents import Agent
from uagents.contrib.protocols.protocol_query import proto_query
from uagents.setup import fund_agent_if_low


Expand All @@ -19,6 +20,7 @@
# build the restaurant agent from stock protocols
restaurant.include(query_proto)
restaurant.include(book_proto)
restaurant.include(proto_query)

TABLES = {
1: TableStatus(seats=2, time_start=16, time_end=22),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uagents"
version = "0.4.1"
version = "0.5.0"
description = "Lightweight framework for rapid agent-based development"
authors = ["Ed FitzGerald <[email protected]>", "James Riehl <[email protected]>", "Alejandro Morales <[email protected]>"]
license = "Apache 2.0"
Expand Down
Loading

0 comments on commit 6c96a94

Please sign in to comment.