Skip to content

Commit

Permalink
Merge branch 'c/async-system-tool-execution' of https://github.com/ju…
Browse files Browse the repository at this point in the history
…lep-ai/julep into c/async-system-tool-execution
  • Loading branch information
HamadaSalhab committed Nov 29, 2024
2 parents 7dcf0ed + 63c3f23 commit 9d68580
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions agents-api/agents_api/activities/execute_system.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
from concurrent.futures import ProcessPoolExecutor
from functools import partial
from typing import Any
from uuid import UUID

Expand All @@ -21,8 +23,6 @@
from ..env import testing
from ..models.developer import get_developer
from .utils import get_handler
from concurrent.futures import ProcessPoolExecutor
from functools import partial

# For running synchronous code in the background
process_pool_executor = ProcessPoolExecutor()
Expand Down Expand Up @@ -114,18 +114,22 @@ async def execute_system(
# In case sessions.create becomes asynchronous in the future
if asyncio.iscoroutinefunction(handler):
return await handler()

# Run the synchronous function in another process
loop = asyncio.get_running_loop()
return await loop.run_in_executor(process_pool_executor, partial(handler, developer_id, session_id, data))
return await loop.run_in_executor(
process_pool_executor, partial(handler, developer_id, session_id, data)
)

# Handle regular operations
if asyncio.iscoroutinefunction(handler):
return await handler(**arguments)

# Run the synchronous function in another process
loop = asyncio.get_running_loop()
return await loop.run_in_executor(process_pool_executor, partial(handler, **arguments))
return await loop.run_in_executor(
process_pool_executor, partial(handler, **arguments)
)
except BaseException as e:
if activity.in_activity():
activity.logger.error(f"Error in execute_system_call: {e}")
Expand Down

0 comments on commit 9d68580

Please sign in to comment.