-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: merge main and resolve conflicts
- Loading branch information
Showing
11 changed files
with
353 additions
and
272 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
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,44 @@ | ||
from cosmpy.aerial.wallet import LocalWallet | ||
|
||
from uagents.network import get_ledger, get_name_service_contract | ||
from uagents.setup import fund_agent_if_low | ||
from uagents import Agent, Context, Model | ||
|
||
|
||
# NOTE: Run agent1.py before running agent2.py | ||
|
||
|
||
class Message(Model): | ||
message: str | ||
|
||
|
||
bob = Agent( | ||
name="bob-0", | ||
seed="agent bob-0 secret phrase", | ||
port=8001, | ||
endpoint=["http://localhost:8001/submit"], | ||
) | ||
|
||
ledger = get_ledger() | ||
my_wallet = LocalWallet.from_unsafe_seed("registration test wallet") | ||
name_service_contract = get_name_service_contract() | ||
DOMAIN = "agent" | ||
|
||
for wallet in [my_wallet, bob.wallet]: | ||
fund_agent_if_low(wallet.address()) | ||
|
||
|
||
@bob.on_event("startup") | ||
async def register_agent_name(ctx: Context): | ||
await name_service_contract.register( | ||
ledger, my_wallet, ctx.address, ctx.name, DOMAIN | ||
) | ||
|
||
|
||
@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}") | ||
|
||
|
||
if __name__ == "__main__": | ||
bob.run() |
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,28 @@ | ||
from uagents.setup import fund_agent_if_low | ||
from uagents import Agent, Context, Model | ||
|
||
|
||
class Message(Model): | ||
message: str | ||
|
||
|
||
alice = Agent( | ||
name="alice-0", | ||
seed="agent alice-0 secret phrase", | ||
port=8000, | ||
endpoint=["http://localhost:8000/submit"], | ||
) | ||
|
||
|
||
fund_agent_if_low(alice.wallet.address()) | ||
|
||
|
||
@alice.on_interval(period=5) | ||
async def alice_interval_handler(ctx: Context): | ||
bob_name = "bob-0.agent" | ||
ctx.logger.info(f"Sending message to {bob_name}...") | ||
await ctx.send(bob_name, Message(message="Hello there bob.")) | ||
|
||
|
||
if __name__ == "__main__": | ||
alice.run() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.