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

chore(core): always return envelope on sync responses #590

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
feat: add timeout to sync response
  • Loading branch information
jrriehl committed Dec 11, 2024
commit a533c59fdd41391b75130c1e365a96120d5bcde7
11 changes: 0 additions & 11 deletions python/docs/api/uagents/communication.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions python/docs/api/uagents/context.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions python/src/uagents/asgi.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
):
Loading