Skip to content

Commit

Permalink
feat: add timeout to sync response
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Dec 11, 2024
1 parent f77f934 commit a533c59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
11 changes: 0 additions & 11 deletions python/docs/api/uagents/communication.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ Method to send an exchange envelope.

Union[MsgStatus, Envelope]: Either the status of the message or the response envelope.

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

#### dispatch`_`sync`_`response`_`envelope

```python
async def dispatch_sync_response_envelope(
env: Envelope) -> Union[MsgStatus, Envelope]
```

Dispatch a synchronous response envelope locally.

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

#### send`_`message`_`raw
Expand Down
10 changes: 6 additions & 4 deletions python/docs/api/uagents/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ Please use the `ctx.agent.address` property instead.
#### send

```python
async def send(destination: str,
message: Model,
sync: bool = False,
timeout: int = DEFAULT_ENVELOPE_TIMEOUT_SECONDS) -> MsgStatus
async def send(
destination: str,
message: Model,
sync: bool = False,
timeout: int = DEFAULT_ENVELOPE_TIMEOUT_SECONDS
) -> Union[MsgStatus, Envelope]
```

This is the pro-active send method which is used in on_event and
Expand Down
6 changes: 4 additions & 2 deletions python/src/uagents/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from requests.structures import CaseInsensitiveDict

from uagents.communication import enclose_response_raw
from uagents.config import RESPONSE_TIME_HINT_SECONDS
from uagents.config import DEFAULT_ENVELOPE_TIMEOUT_SECONDS, RESPONSE_TIME_HINT_SECONDS
from uagents.context import ERROR_MESSAGE_DIGEST
from uagents.crypto import is_user_address
from uagents.dispatch import dispatcher
Expand Down Expand Up @@ -361,7 +361,9 @@ async def __call__(self, scope, receive, send): # pylint: disable=too-many-bra

# wait for any queries to be resolved
if expects_response:
response_msg, schema_digest = await self._queries[env.sender]
response_msg, schema_digest = await asyncio.wait_for(
self._queries[env.sender], DEFAULT_ENVELOPE_TIMEOUT_SECONDS
)
if (env.expires is not None) and (
datetime.now() > datetime.fromtimestamp(env.expires)
):
Expand Down

0 comments on commit a533c59

Please sign in to comment.