-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into d/announcement-update
- Loading branch information
Showing
4 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 37 additions & 8 deletions
45
agents-api/agents_api/activities/task_steps/tool_call_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import base64 | ||
import secrets | ||
|
||
from beartype import beartype | ||
from temporalio import activity | ||
|
||
from ...activities.task_steps import base_evaluate | ||
from ...autogen.openapi_model import ToolCallStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
|
||
|
||
def generate_call_id(): | ||
# Generate 18 random bytes (which will result in 24 base64 characters) | ||
random_bytes = secrets.token_bytes(18) | ||
# Encode to base64 and remove padding | ||
base64_string = base64.urlsafe_b64encode(random_bytes).decode("ascii").rstrip("=") | ||
# Add the "call_" prefix | ||
return f"call_{base64_string}" | ||
|
||
|
||
@activity.defn | ||
@beartype | ||
async def tool_call_step(context: StepContext) -> dict: | ||
raise NotImplementedError() | ||
# assert isinstance(context.current_step, ToolCallStep) | ||
async def tool_call_step(context: StepContext) -> StepOutcome: | ||
assert isinstance(context.current_step, ToolCallStep) | ||
|
||
tool_type, tool_name = context.current_step.tool.split(".") | ||
arguments = await base_evaluate( | ||
context.current_step.arguments, context.model_dump() | ||
) | ||
|
||
tools = context.execution_input.tools | ||
|
||
assert tool_name in [tool.name for tool in tools], f"Tool {tool_name} not found" | ||
|
||
call_id = generate_call_id() | ||
|
||
# context.current_step.tool_id | ||
# context.current_step.arguments | ||
# # get tool by id | ||
# # call tool | ||
tool_call = { | ||
tool_type: { | ||
"arguments": arguments, | ||
"name": tool_name, | ||
}, | ||
"id": call_id, | ||
"type": tool_type, | ||
} | ||
|
||
# return {} | ||
return StepOutcome(output=tool_call) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters