Skip to content

Commit

Permalink
chore: update agent mailbox key (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl authored Nov 16, 2023
1 parent 47753d7 commit 6c4a4d7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 37 deletions.
7 changes: 4 additions & 3 deletions python/examples/11-mailbox-agents/alice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ class Message(Model):
# Copy the address shown below
print(f"Your agent's address is: {Agent(seed=SEED_PHRASE).address}")

# Then sign up at https://agentverse.ai to get an API key and register your agent
API_KEY = "put_your_API_key_here"
# Then go to https://agentverse.ai, register your agent in the Mailroom
# and copy the agent's mailbox key
AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"

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


Expand Down
7 changes: 4 additions & 3 deletions python/examples/11-mailbox-agents/bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class Message(Model):
# Copy the address shown below
print(f"Your agent's address is: {Agent(seed=SEED_PHRASE).address}")

# Then go to https://agentverse.ai to get your API key and register a second agent
API_KEY = "put_your_API_key_here"
# Then go to https://agentverse.ai, register your agent in the Mailroom
# and copy the agent's mailbox key
AGENT_MAILBOX_KEY = "put_your_AGENT_MAILBOX_KEY_here"

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


Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "uagents"
version = "0.8.0"
version = "0.8.1"
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
12 changes: 6 additions & 6 deletions python/src/uagents/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,31 @@ def parse_agentverse_config(
Returns:
Dict[str, str]: The parsed agentverse configuration.
"""
api_key = None
agent_mailbox_key = None
base_url = AGENTVERSE_URL
protocol = None
protocol_override = None
if isinstance(config, str):
if config.count("@") == 1:
api_key, base_url = config.split("@")
agent_mailbox_key, base_url = config.split("@")
elif "://" in config:
base_url = config
else:
api_key = config
agent_mailbox_key = config
elif isinstance(config, dict):
api_key = config.get("api_key")
agent_mailbox_key = config.get("agent_mailbox_key")
base_url = config.get("base_url") or base_url
protocol_override = config.get("protocol")
if "://" in base_url:
protocol, base_url = base_url.split("://")
protocol = protocol_override or protocol or "https"
http_prefix = "https" if protocol in {"wss", "https"} else "http"
return {
"api_key": api_key,
"agent_mailbox_key": agent_mailbox_key,
"base_url": base_url,
"protocol": protocol,
"http_prefix": http_prefix,
"use_mailbox": api_key is not None,
"use_mailbox": agent_mailbox_key is not None,
}


Expand Down
10 changes: 5 additions & 5 deletions python/src/uagents/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def base_url(self):
return self._agent.mailbox["base_url"]

@property
def api_key(self):
def agent_mailbox_key(self):
"""
Property to access the api key of the mailbox server.
Property to access the agent_mailbox_key of the mailbox server.
Returns: The api key of the mailbox server.
Returns: The agent_mailbox_key of the mailbox server.
"""
return self._agent.mailbox["api_key"]
return self._agent.mailbox["agent_mailbox_key"]

@property
def protocol(self):
Expand Down Expand Up @@ -215,7 +215,7 @@ async def _get_access_token(self):
data=json.dumps(
{
"address": self._agent.address,
"api_key": self.api_key,
"agent_mailbox_key": self.agent_mailbox_key,
"challenge": challenge,
"challenge_response": self._agent.sign(challenge.encode()),
}
Expand Down
2 changes: 1 addition & 1 deletion python/src/uagents/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def register_agent_with_mailbox(agent: Agent, email: str):
)
if resp.status_code == 200:
LOGGER.info("Registered agent on mailbox server")
mailbox["api_key"] = resp.json()["api_key"]
mailbox["agent_mailbox_key"] = resp.json()["agent_mailbox_key"]
else:
LOGGER.exception("Failed to register agent on mailbox server")
36 changes: 18 additions & 18 deletions python/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,99 @@

agents = [
Agent(),
Agent(mailbox="api_key@some_url"),
Agent(mailbox={"api_key": "api_key", "base_url": "some_url"}),
Agent(mailbox="api_key"),
Agent(agentverse="api_key@some_url"),
Agent(agentverse="api_key"),
Agent(mailbox="agent_mailbox_key@some_url"),
Agent(mailbox={"agent_mailbox_key": "agent_mailbox_key", "base_url": "some_url"}),
Agent(mailbox="agent_mailbox_key"),
Agent(agentverse="agent_mailbox_key@some_url"),
Agent(agentverse="agent_mailbox_key"),
Agent(agentverse="http://some_url"),
Agent(agentverse="wss://some_url"),
Agent(agentverse="ws://some_url"),
Agent(agentverse={"api_key": "api_key", "protocol": "wss"}),
Agent(agentverse={"agent_mailbox_key": "agent_mailbox_key", "protocol": "wss"}),
Agent(agentverse="https://staging.agentverse.ai"),
Agent(agentverse={"base_url": "staging.agentverse.ai"}),
]

expected_configs = [
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "agentverse.ai",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": False,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "some_url",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "some_url",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "agentverse.ai",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "some_url",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "agentverse.ai",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "some_url",
"protocol": "http",
"http_prefix": "http",
"use_mailbox": False,
},
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "some_url",
"protocol": "wss",
"http_prefix": "https",
"use_mailbox": False,
},
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "some_url",
"protocol": "ws",
"http_prefix": "http",
"use_mailbox": False,
},
{
"api_key": "api_key",
"agent_mailbox_key": "agent_mailbox_key",
"base_url": "agentverse.ai",
"protocol": "wss",
"http_prefix": "https",
"use_mailbox": True,
},
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "staging.agentverse.ai",
"protocol": "https",
"http_prefix": "https",
"use_mailbox": False,
},
{
"api_key": None,
"agent_mailbox_key": None,
"base_url": "staging.agentverse.ai",
"protocol": "https",
"http_prefix": "https",
Expand Down

0 comments on commit 6c4a4d7

Please sign in to comment.