mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-23 02:12:26 +00:00
working end to end client sdk tests with custom tools
This commit is contained in:
parent
1a66ddc1b5
commit
4dd2f4c363
5 changed files with 304 additions and 149 deletions
|
|
@ -400,6 +400,10 @@ class ChatAgent(ShieldRunnerMixin):
|
|||
output_attachments = []
|
||||
|
||||
n_iter = 0
|
||||
# Build a map of custom tools to their definitions for faster lookup
|
||||
custom_tools = {}
|
||||
for tool in self.agent_config.custom_tools:
|
||||
custom_tools[tool.name] = tool
|
||||
while True:
|
||||
msg = input_messages[-1]
|
||||
|
||||
|
|
@ -530,6 +534,9 @@ class ChatAgent(ShieldRunnerMixin):
|
|||
else:
|
||||
log.info(f"{str(message)}")
|
||||
tool_call = message.tool_calls[0]
|
||||
if tool_call.tool_name in custom_tools:
|
||||
yield message
|
||||
return
|
||||
|
||||
step_id = str(uuid.uuid4())
|
||||
yield AgentTurnResponseStreamChunk(
|
||||
|
|
@ -619,6 +626,22 @@ class ChatAgent(ShieldRunnerMixin):
|
|||
|
||||
async def _get_tools(self) -> List[ToolDefinition]:
|
||||
ret = []
|
||||
for tool in self.agent_config.custom_tools:
|
||||
params = {}
|
||||
for param in tool.parameters:
|
||||
params[param.name] = ToolParamDefinition(
|
||||
param_type=param.parameter_type,
|
||||
description=param.description,
|
||||
required=param.required,
|
||||
default=param.default,
|
||||
)
|
||||
ret.append(
|
||||
ToolDefinition(
|
||||
tool_name=tool.name,
|
||||
description=tool.description,
|
||||
parameters=params,
|
||||
)
|
||||
)
|
||||
for tool_name in self.agent_config.available_tools:
|
||||
tool = await self.tool_groups_api.get_tool(tool_name)
|
||||
if tool.built_in_type:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue