Skip to content

Commit d1e35d9

Browse files
committed
comments
1 parent 32062de commit d1e35d9

File tree

1 file changed

+61
-3
lines changed
  • src/llama_stack_client/lib/agents

1 file changed

+61
-3
lines changed

src/llama_stack_client/lib/agents/agent.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,69 @@ def _create_turn_streaming(
316316
class AsyncAgent:
317317
def __init__(
318318
self,
319-
client: AsyncLlamaStackClient,
320-
agent_config: AgentConfig,
321-
client_tools: Tuple[ClientTool] = (),
319+
client: LlamaStackClient,
320+
# begin deprecated
321+
agent_config: Optional[AgentConfig] = None,
322+
client_tools: Tuple[ClientTool, ...] = (),
323+
# end deprecated
322324
tool_parser: Optional[ToolParser] = None,
325+
model: Optional[str] = None,
326+
instructions: Optional[str] = None,
327+
tools: Optional[List[Union[Toolgroup, ClientTool]]] = None,
328+
tool_config: Optional[ToolConfig] = None,
329+
sampling_params: Optional[SamplingParams] = None,
330+
max_infer_iters: Optional[int] = None,
331+
input_shields: Optional[List[str]] = None,
332+
output_shields: Optional[List[str]] = None,
333+
response_format: Optional[ResponseFormat] = None,
334+
enable_session_persistence: Optional[bool] = None,
323335
):
336+
"""Construct an Agent with the given parameters.
337+
338+
:param client: The LlamaStackClient instance.
339+
:param agent_config: The AgentConfig instance.
340+
::deprecated: use other parameters instead
341+
:param client_tools: A tuple of ClientTool instances.
342+
::deprecated: use tools instead
343+
:param tool_parser: Custom logic that parses tool calls from a message.
344+
:param model: The model to use for the agent.
345+
:param instructions: The instructions for the agent.
346+
:param tools: A list of tools for the agent. Values can be one of the following:
347+
- dict representing a toolgroup/tool with arguments: e.g. {"name": "builtin::rag/knowledge_search", "args": {"vector_db_ids": [123]}}
348+
- a python function decorated with @client_tool
349+
- str representing a tool within a toolgroup: e.g. "builtin::rag/knowledge_search"
350+
- str representing a toolgroup_id: e.g. "builtin::rag", "builtin::code_interpreter", where all tools in the toolgroup will be added to the agent
351+
- an instance of ClientTool: A client tool object.
352+
:param tool_config: The tool configuration for the agent.
353+
:param sampling_params: The sampling parameters for the agent.
354+
:param max_infer_iters: The maximum number of inference iterations.
355+
:param input_shields: The input shields for the agent.
356+
:param output_shields: The output shields for the agent.
357+
:param response_format: The response format for the agent.
358+
:param enable_session_persistence: Whether to enable session persistence.
359+
"""
324360
self.client = client
361+
362+
if agent_config is not None:
363+
logger.warning("`agent_config` is deprecated. Use inlined parameters instead.")
364+
if client_tools != ():
365+
logger.warning("`client_tools` is deprecated. Use `tools` instead.")
366+
367+
# Construct agent_config from parameters if not provided
368+
if agent_config is None:
369+
agent_config = AgentUtils.get_agent_config(
370+
model=model,
371+
instructions=instructions,
372+
tools=tools,
373+
tool_config=tool_config,
374+
sampling_params=sampling_params,
375+
max_infer_iters=max_infer_iters,
376+
input_shields=input_shields,
377+
output_shields=output_shields,
378+
response_format=response_format,
379+
enable_session_persistence=enable_session_persistence,
380+
)
381+
325382
self.agent_config = agent_config
326383
self.client_tools = {t.get_name(): t for t in client_tools}
327384
self.sessions = []
@@ -341,6 +398,7 @@ async def initialize(self) -> None:
341398
self.builtin_tools[tool.identifier] = tool
342399

343400
async def create_session(self, session_name: str) -> str:
401+
await self.initialize()
344402
agentic_system_create_session_response = await self.client.agents.session.create(
345403
agent_id=self.agent_id,
346404
session_name=session_name,

0 commit comments

Comments
 (0)