Skip to content

Commit 61b70b9

Browse files
fix: No context vars for async agents replies
1 parent 9d581de commit 61b70b9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: autogen/agentchat/conversable_agent.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import contextvars
23
import copy
34
import functools
45
import inspect
@@ -1486,6 +1487,7 @@ async def a_generate_oai_reply(
14861487
) -> Tuple[bool, Union[str, Dict, None]]:
14871488
"""Generate a reply using autogen.oai asynchronously."""
14881489
iostream = IOStream.get_default()
1490+
parent_context = contextvars.copy_context()
14891491

14901492
def _generate_oai_reply(
14911493
self, iostream: IOStream, *args: Any, **kwargs: Any
@@ -1495,7 +1497,7 @@ def _generate_oai_reply(
14951497

14961498
return await asyncio.get_event_loop().run_in_executor(
14971499
None,
1498-
functools.partial(
1500+
lambda: parent_context.run(
14991501
_generate_oai_reply, self=self, iostream=iostream, messages=messages, sender=sender, config=config
15001502
),
15011503
)

0 commit comments

Comments
 (0)