Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add message endpoint for inspector #490

Merged
merged 33 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
381cdb9
feat(core): add message endpoint for inspector
Alejandro-Morales Aug 7, 2024
4e6ffd2
fix: ruff check
Alejandro-Morales Aug 7, 2024
8f53362
fix: ruff check
Alejandro-Morales Aug 7, 2024
f4acd8c
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 15, 2024
bd8d4cc
feat: move file storage to memory storage
Alejandro-Morales Aug 15, 2024
f13f0c4
fix: ruff check
Alejandro-Morales Aug 16, 2024
c899ca5
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 16, 2024
2a1e27d
updates on Florians comments
Alejandro-Morales Aug 16, 2024
613c257
ruff format
Alejandro-Morales Aug 16, 2024
7a78622
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 16, 2024
7dd0098
feat: updates on florians comments and agent_info endpoint
Alejandro-Morales Aug 19, 2024
b40656a
fix: delete unused imports
Alejandro-Morales Aug 19, 2024
474d5bd
fix: ruff format check
Alejandro-Morales Aug 19, 2024
d244919
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 19, 2024
c6e5e62
feat: add retention mechanism
Alejandro-Morales Aug 19, 2024
5dc4996
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 21, 2024
f43ab1c
feat: Bureau integration
Alejandro-Morales Aug 22, 2024
46aea4c
try adding server headers
Archento Aug 22, 2024
e37ee6a
fix: format
Alejandro-Morales Aug 22, 2024
05f08e8
fix: model dump agent endpoint list
jrriehl Aug 23, 2024
0e3c4d1
loosen access control rules
Archento Aug 23, 2024
724ede6
Merge branch 'main' into feat/message-inspector
Alejandro-Morales Aug 28, 2024
e65f152
feat: Refactoring based on new REST updates
Alejandro-Morales Aug 28, 2024
39f87b5
fix: test and ruff check
Alejandro-Morales Aug 28, 2024
ead3242
minor corrections
Alejandro-Morales Aug 28, 2024
01b075f
fix rest example, make inspector opt-out, enforce reserved routes, wr…
Archento Aug 29, 2024
887c3f7
fix test
Archento Aug 29, 2024
2999472
simplify AgentEndpoint model
Archento Aug 29, 2024
bec7141
relocate cache ref to dispenser
Archento Aug 30, 2024
a593e94
update docs
Archento Aug 30, 2024
4bcf5e8
fix: small context inconsistency
Archento Aug 30, 2024
0c72136
another small revert in context
Archento Aug 30, 2024
a28162e
refactor retention mechanism
Archento Aug 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions python/docs/api/uagents/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ An agent that interacts within a communication environment.
- `_signed_message_handlers` _Dict[str, MessageCallback]_ - Handlers for signed messages.
- `_unsigned_message_handlers` _Dict[str, MessageCallback]_ - Handlers for
unsigned messages.
- `_message_cache` _EnvelopeHistory_ - History of messages received by the agent.
- `_models` _Dict[str, Type[Model]]_ - Dictionary mapping supported message digests to messages.
- `_replies` _Dict[str, Dict[str, Type[Model]]]_ - Dictionary of allowed replies for each type
of incoming message.
Expand Down Expand Up @@ -183,13 +184,15 @@ def __init__(name: Optional[str] = None,
agentverse: Optional[Union[str, Dict[str, str]]] = None,
mailbox: Optional[Union[str, Dict[str, str]]] = None,
resolve: Optional[Resolver] = None,
registration_policy: Optional[AgentRegistrationPolicy] = None,
enable_wallet_messaging: Union[bool, Dict[str, str]] = False,
wallet_key_derivation_index: Optional[int] = 0,
max_resolver_endpoints: Optional[int] = None,
version: Optional[str] = None,
test: bool = True,
loop: Optional[asyncio.AbstractEventLoop] = None,
log_level: Union[int, str] = logging.INFO)
log_level: Union[int, str] = logging.INFO,
enable_agent_inspector: bool = True)
```

Initialize an Agent instance.
Expand All @@ -212,6 +215,7 @@ Initialize an Agent instance.
- `test` _Optional[bool]_ - True if the agent will register and transact on the testnet.
- `loop` _Optional[asyncio.AbstractEventLoop]_ - The asyncio event loop to use.
- `log_level` _Union[int, str]_ - The logging level for the agent.
- `enable_agent_inspector` _bool_ - Enable the agent inspector for debugging.

<a id="src.uagents.agent.Agent.initialize_wallet_messaging"></a>

Expand Down Expand Up @@ -462,7 +466,6 @@ Sign the registration data for Almanac contract.
**Returns**:

- `str` - The signature of the registration data.


**Raises**:

Expand Down Expand Up @@ -671,12 +674,30 @@ Handle an incoming message.
- `message` _JsonStr_ - The message content in JSON format.
- `session` _uuid.UUID_ - The session UUID.

<a id="src.uagents.agent.Agent.handle_rest"></a>

#### handle`_`rest

```python
async def handle_rest(
method: RestMethod, endpoint: str,
message: Optional[Model]) -> Optional[Union[Dict[str, Any], Model]]
```

Handle a REST request.

**Arguments**:

- `method` _RestMethod_ - The REST method.
- `endpoint` _str_ - The REST endpoint.
- `message` _Model_ - The message content.

<a id="src.uagents.agent.Agent.setup"></a>

#### setup

```python
def setup()
async def setup()
```

Include the internal agent protocol, run startup tasks, and start background tasks.
Expand Down Expand Up @@ -711,6 +732,16 @@ def start_message_receivers()

Start message receiving tasks for the agent.

<a id="src.uagents.agent.Agent.run_async"></a>

#### run`_`async

```python
async def run_async()
```

Create all tasks for the agent.

<a id="src.uagents.agent.Agent.run"></a>

#### run
Expand Down Expand Up @@ -774,6 +805,7 @@ This class manages a collection of agents and orchestrates their execution.
def __init__(agents: Optional[List[Agent]] = None,
port: Optional[int] = None,
endpoint: Optional[Union[str, List[str], Dict[str, dict]]] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
log_level: Union[int, str] = logging.INFO)
```

Expand All @@ -799,6 +831,16 @@ Add an agent to the bureau.

- `agent` _Agent_ - The agent to be added.

<a id="src.uagents.agent.Bureau.run_async"></a>

#### run`_`async

```python
async def run_async()
```

Run the agents managed by the bureau.

<a id="src.uagents.agent.Bureau.run"></a>

#### run
Expand All @@ -807,5 +849,5 @@ Add an agent to the bureau.
def run()
```

Run the agents managed by the bureau.
Run the bureau.

22 changes: 22 additions & 0 deletions python/docs/api/uagents/asgi.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ Property to access the underlying uvicorn server.

Returns: The server.

<a id="src.uagents.asgi.ASGIServer.add_rest_endpoint"></a>

#### add`_`rest`_`endpoint

```python
def add_rest_endpoint(address: str, method: RestMethod, endpoint: str,
request: Optional[Type[Model]],
response: Type[Union[Model, BaseModel]])
```

Add a REST endpoint to the server.

<a id="src.uagents.asgi.ASGIServer.has_rest_endpoint"></a>

#### has`_`rest`_`endpoint

```python
def has_rest_endpoint(method: RestMethod, endpoint: str) -> bool
```

Check if the server has a REST endpoint registered.

<a id="src.uagents.asgi.ASGIServer.handle_readiness_probe"></a>

#### handle`_`readiness`_`probe
Expand Down
49 changes: 2 additions & 47 deletions python/docs/api/uagents/communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,6 @@

Agent dispatch of exchange envelopes and synchronous messages.

<a id="src.uagents.communication.DeliveryStatus"></a>

## DeliveryStatus Objects

```python
class DeliveryStatus(str, Enum)
```

Delivery status of a message.

<a id="src.uagents.communication.MsgDigest"></a>

## MsgDigest Objects

```python
@dataclass
class MsgDigest()
```

Represents a message digest containing a message and its schema digest.

**Attributes**:

- `message` _Any_ - The message content.
- `schema_digest` _str_ - The schema digest of the message.

<a id="src.uagents.communication.MsgStatus"></a>

## MsgStatus Objects

```python
@dataclass
class MsgStatus()
```

Represents the status of a sent message.

**Attributes**:

- `status` _str_ - The delivery status of the message {'sent', 'delivered', 'failed'}.
- `detail` _str_ - The details of the message delivery.
- `destination` _str_ - The destination address of the message.
- `endpoint` _str_ - The endpoint the message was sent to.
- `session` _Optional[uuid.UUID]_ - The session ID of the message.

<a id="src.uagents.communication.Dispenser"></a>

## Dispenser Objects
Expand Down Expand Up @@ -251,7 +206,7 @@ Standalone function to send a synchronous message to an agent.
def enclose_response(message: Model,
sender: str,
session: UUID4,
target: str = "") -> str
target: str = "") -> JsonStr
```

Enclose a response message within an envelope.
Expand All @@ -277,7 +232,7 @@ def enclose_response_raw(json_message: JsonStr,
schema_digest: str,
sender: str,
session: UUID4,
target: str = "") -> str
target: str = "") -> JsonStr
```

Enclose a raw response message within an envelope.
Expand Down
18 changes: 18 additions & 0 deletions python/docs/api/uagents/envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,21 @@ Verify the envelope's signature.
- `ValueError` - If the signature is missing.
- `ecdsa.BadSignatureError` - If the signature is invalid.

<a id="src.uagents.envelope.EnvelopeHistory"></a>

## EnvelopeHistory Objects

```python
class EnvelopeHistory(BaseModel)
```

<a id="src.uagents.envelope.EnvelopeHistory.apply_retention_policy"></a>

#### apply`_`retention`_`policy

```python
def apply_retention_policy()
```

Remove entries older than 24 hours

10 changes: 10 additions & 0 deletions python/docs/api/uagents/mailbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ Returns: The http prefix of the mailbox server {http, https}.
async def run()
```

Runs the mailbox client.

<a id="src.uagents.mailbox.MailboxClient.start_polling"></a>

#### start`_`polling

```python
async def start_polling()
```

Runs the mailbox client. Acquires an access token if needed and then starts a polling loop.

<a id="src.uagents.mailbox.MailboxClient.process_deletion_queue"></a>
Expand Down
16 changes: 16 additions & 0 deletions python/docs/api/uagents/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ Register a name within a domain using the NameService contract.
addresses registered to the domain. If False, the address will be
appended to the previous records. Defaults to True.

<a id="src.uagents.network.NameServiceContract.unregister"></a>

#### unregister

```python
async def unregister(name: str, domain: str, wallet: LocalWallet)
```

Unregister a name within a domain using the NameService contract.

**Arguments**:

- `name` _str_ - The name to be unregistered.
- `domain` _str_ - The domain in which the name is registered.
- `wallet` _LocalWallet_ - The wallet of the agent.

<a id="src.uagents.network.get_name_service_contract"></a>

#### get`_`name`_`service`_`contract
Expand Down
49 changes: 49 additions & 0 deletions python/docs/api/uagents/types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<a id="src.uagents.types"></a>

# src.uagents.types

<a id="src.uagents.types.DeliveryStatus"></a>

## DeliveryStatus Objects

```python
class DeliveryStatus(str, Enum)
```

Delivery status of a message.

<a id="src.uagents.types.MsgDigest"></a>

## MsgDigest Objects

```python
@dataclass
class MsgDigest()
```

Represents a message digest containing a message and its schema digest.

**Attributes**:

- `message` _Any_ - The message content.
- `schema_digest` _str_ - The schema digest of the message.

<a id="src.uagents.types.MsgStatus"></a>

## MsgStatus Objects

```python
@dataclass
class MsgStatus()
```

Represents the status of a sent message.

**Attributes**:

- `status` _str_ - The delivery status of the message {'sent', 'delivered', 'failed'}.
- `detail` _str_ - The details of the message delivery.
- `destination` _str_ - The destination address of the message.
- `endpoint` _str_ - The endpoint the message was sent to.
- `session` _Optional[uuid.UUID]_ - The session ID of the message.

8 changes: 4 additions & 4 deletions python/examples/19-rest-api/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
import time
from typing import Any, Dict

from uagents import Agent, Context, Model
Expand All @@ -9,7 +9,7 @@ class Request(Model):


class Response(Model):
timestamp: datetime
timestamp: int
text: str
agent_address: str

Expand All @@ -26,7 +26,7 @@ class EmptyMessage(Model):
async def handle_get(ctx: Context) -> Dict[str, Any]:
ctx.logger.info("Received GET request")
return {
"timestamp": datetime.now(),
"timestamp": int(time.time()),
"text": "Hello from the GET handler!",
"agent_address": ctx.agent.address,
}
Expand All @@ -38,7 +38,7 @@ async def handle_post(ctx: Context, req: Request) -> Response:
return Response(
text=f"Received: {req.text}",
agent_address=ctx.agent.address,
timestamp=datetime.now(),
timestamp=int(time.time()),
)


Expand Down
Loading
Loading