tool calling working now

This commit is contained in:
Kai Wu 2024-11-07 18:47:47 -08:00
parent 45e9e3ac4a
commit bb475d58ae
2 changed files with 61 additions and 55 deletions

View file

@ -109,14 +109,15 @@
"Query: What are the latest developments in quantum computing?\n",
"--------------------------------------------------\n",
"\u001b[30m\u001b[0m\u001b[33minference> \u001b[0m\u001b[33mF\u001b[0m\u001b[33mIND\u001b[0m\u001b[33mINGS\u001b[0m\u001b[33m:\n",
"\u001b[0m\u001b[33mThe\u001b[0m\u001b[33m latest\u001b[0m\u001b[33m developments\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computing\u001b[0m\u001b[33m include\u001b[0m\u001b[33m advancements\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m processors\u001b[0m\u001b[33m,\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m algorithms\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Researchers\u001b[0m\u001b[33m have\u001b[0m\u001b[33m made\u001b[0m\u001b[33m progress\u001b[0m\u001b[33m in\u001b[0m\u001b[33m building\u001b[0m\u001b[33m larger\u001b[0m\u001b[33m and\u001b[0m\u001b[33m more\u001b[0m\u001b[33m stable\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m processors\u001b[0m\u001b[33m,\u001b[0m\u001b[33m such\u001b[0m\u001b[33m as\u001b[0m\u001b[33m Google\u001b[0m\u001b[33m's\u001b[0m\u001b[33m \u001b[0m\u001b[33m53\u001b[0m\u001b[33m-q\u001b[0m\u001b[33mubit\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m and\u001b[0m\u001b[33m IBM\u001b[0m\u001b[33m's\u001b[0m\u001b[33m \u001b[0m\u001b[33m127\u001b[0m\u001b[33m-q\u001b[0m\u001b[33mubit\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m (\u001b[0m\u001b[33m1\u001b[0m\u001b[33m).\u001b[0m\u001b[33m New\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m algorithms\u001b[0m\u001b[33m,\u001b[0m\u001b[33m like\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Quantum\u001b[0m\u001b[33m Approx\u001b[0m\u001b[33mimate\u001b[0m\u001b[33m Optimization\u001b[0m\u001b[33m Algorithm\u001b[0m\u001b[33m (\u001b[0m\u001b[33mQ\u001b[0m\u001b[33mAO\u001b[0m\u001b[33mA\u001b[0m\u001b[33m),\u001b[0m\u001b[33m have\u001b[0m\u001b[33m been\u001b[0m\u001b[33m developed\u001b[0m\u001b[33m to\u001b[0m\u001b[33m solve\u001b[0m\u001b[33m complex\u001b[0m\u001b[33m optimization\u001b[0m\u001b[33m problems\u001b[0m\u001b[33m (\u001b[0m\u001b[33m2\u001b[0m\u001b[33m).\u001b[0m\u001b[33m Additionally\u001b[0m\u001b[33m,\u001b[0m\u001b[33m researchers\u001b[0m\u001b[33m are\u001b[0m\u001b[33m exploring\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m techniques\u001b[0m\u001b[33m to\u001b[0m\u001b[33m mitigate\u001b[0m\u001b[33m errors\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computations\u001b[0m\u001b[33m (\u001b[0m\u001b[33m3\u001b[0m\u001b[33m).\n",
"\u001b[0m\u001b[33mThe\u001b[0m\u001b[33m latest\u001b[0m\u001b[33m developments\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computing\u001b[0m\u001b[33m include\u001b[0m\u001b[33m the\u001b[0m\u001b[33m introduction\u001b[0m\u001b[33m of\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m processors\u001b[0m\u001b[33m with\u001b[0m\u001b[33m increasing\u001b[0m\u001b[33m numbers\u001b[0m\u001b[33m of\u001b[0m\u001b[33m q\u001b[0m\u001b[33mubits\u001b[0m\u001b[33m,\u001b[0m\u001b[33m advancements\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m the\u001b[0m\u001b[33m development\u001b[0m\u001b[33m of\u001b[0m\u001b[33m new\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m algorithms\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Companies\u001b[0m\u001b[33m such\u001b[0m\u001b[33m as\u001b[0m\u001b[33m IBM\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Google\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m Microsoft\u001b[0m\u001b[33m are\u001b[0m\u001b[33m leading\u001b[0m\u001b[33m the\u001b[0m\u001b[33m charge\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computing\u001b[0m\u001b[33m research\u001b[0m\u001b[33m and\u001b[0m\u001b[33m development\u001b[0m\u001b[33m.\u001b[0m\u001b[33m For\u001b[0m\u001b[33m example\u001b[0m\u001b[33m,\u001b[0m\u001b[33m IBM\u001b[0m\u001b[33m's\u001b[0m\u001b[33m Quantum\u001b[0m\u001b[33m Experience\u001b[0m\u001b[33m cloud\u001b[0m\u001b[33m-based\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computer\u001b[0m\u001b[33m has\u001b[0m\u001b[33m \u001b[0m\u001b[33m127\u001b[0m\u001b[33m q\u001b[0m\u001b[33mubits\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mwww\u001b[0m\u001b[33m.ibm\u001b[0m\u001b[33m.com\u001b[0m\u001b[33m/\u001b[0m\u001b[33mquant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m-com\u001b[0m\u001b[33mput\u001b[0m\u001b[33ming\u001b[0m\u001b[33m/\u001b[0m\u001b[33m),\u001b[0m\u001b[33m while\u001b[0m\u001b[33m Google\u001b[0m\u001b[33m's\u001b[0m\u001b[33m S\u001b[0m\u001b[33myc\u001b[0m\u001b[33mam\u001b[0m\u001b[33more\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m has\u001b[0m\u001b[33m \u001b[0m\u001b[33m53\u001b[0m\u001b[33m q\u001b[0m\u001b[33mubits\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33ms\u001b[0m\u001b[33mcai\u001b[0m\u001b[33m.st\u001b[0m\u001b[33manford\u001b[0m\u001b[33m.edu\u001b[0m\u001b[33m/~\u001b[0m\u001b[33mmw\u001b[0m\u001b[33mj\u001b[0m\u001b[33m/s\u001b[0m\u001b[33myc\u001b[0m\u001b[33mam\u001b[0m\u001b[33more\u001b[0m\u001b[33m.html\u001b[0m\u001b[33m).\n",
"\n",
"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m is\u001b[0m\u001b[33m also\u001b[0m\u001b[33m a\u001b[0m\u001b[33m major\u001b[0m\u001b[33m area\u001b[0m\u001b[33m of\u001b[0m\u001b[33m research\u001b[0m\u001b[33m,\u001b[0m\u001b[33m with\u001b[0m\u001b[33m scientists\u001b[0m\u001b[33m exploring\u001b[0m\u001b[33m various\u001b[0m\u001b[33m methods\u001b[0m\u001b[33m to\u001b[0m\u001b[33m mitigate\u001b[0m\u001b[33m the\u001b[0m\u001b[33m effects\u001b[0m\u001b[33m of\u001b[0m\u001b[33m deco\u001b[0m\u001b[33mherence\u001b[0m\u001b[33m and\u001b[0m\u001b[33m errors\u001b[0m\u001b[33m in\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computations\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mar\u001b[0m\u001b[33mxiv\u001b[0m\u001b[33m.org\u001b[0m\u001b[33m/\u001b[0m\u001b[33mabs\u001b[0m\u001b[33m/\u001b[0m\u001b[33m210\u001b[0m\u001b[33m4\u001b[0m\u001b[33m.\u001b[0m\u001b[33m045\u001b[0m\u001b[33m93\u001b[0m\u001b[33m).\u001b[0m\u001b[33m New\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m algorithms\u001b[0m\u001b[33m,\u001b[0m\u001b[33m such\u001b[0m\u001b[33m as\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m simulation\u001b[0m\u001b[33m and\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m machine\u001b[0m\u001b[33m learning\u001b[0m\u001b[33m,\u001b[0m\u001b[33m are\u001b[0m\u001b[33m also\u001b[0m\u001b[33m being\u001b[0m\u001b[33m developed\u001b[0m\u001b[33m to\u001b[0m\u001b[33m take\u001b[0m\u001b[33m advantage\u001b[0m\u001b[33m of\u001b[0m\u001b[33m the\u001b[0m\u001b[33m unique\u001b[0m\u001b[33m properties\u001b[0m\u001b[33m of\u001b[0m\u001b[33m quantum\u001b[0m\u001b[33m computing\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mar\u001b[0m\u001b[33mxiv\u001b[0m\u001b[33m.org\u001b[0m\u001b[33m/\u001b[0m\u001b[33mabs\u001b[0m\u001b[33m/\u001b[0m\u001b[33m210\u001b[0m\u001b[33m2\u001b[0m\u001b[33m.\u001b[0m\u001b[33m081\u001b[0m\u001b[33m83\u001b[0m\u001b[33m).\n",
"\n",
"\u001b[0m\u001b[33mS\u001b[0m\u001b[33mOURCES\u001b[0m\u001b[33m:\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m computing\u001b[0m\u001b[33m:\u001b[0m\u001b[33m a\u001b[0m\u001b[33m very\u001b[0m\u001b[33m short\u001b[0m\u001b[33m introduction\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m by\u001b[0m\u001b[33m Samuel\u001b[0m\u001b[33m J\u001b[0m\u001b[33m.\u001b[0m\u001b[33m L\u001b[0m\u001b[33momon\u001b[0m\u001b[33maco\u001b[0m\u001b[33m (\u001b[0m\u001b[33mURL\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m Approx\u001b[0m\u001b[33mimate\u001b[0m\u001b[33m Optimization\u001b[0m\u001b[33m Algorithm\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m by\u001b[0m\u001b[33m Edward\u001b[0m\u001b[33m Far\u001b[0m\u001b[33mhi\u001b[0m\u001b[33m et\u001b[0m\u001b[33m al\u001b[0m\u001b[33m.\u001b[0m\u001b[33m (\u001b[0m\u001b[33mURL\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m for\u001b[0m\u001b[33m beginners\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m by\u001b[0m\u001b[33m Robert\u001b[0m\u001b[33m A\u001b[0m\u001b[33m.\u001b[0m\u001b[33m H\u001b[0m\u001b[33mulet\u001b[0m\u001b[33m (\u001b[0m\u001b[33mURL\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mGoogle\u001b[0m\u001b[33m's\u001b[0m\u001b[33m \u001b[0m\u001b[33m53\u001b[0m\u001b[33m-q\u001b[0m\u001b[33mubit\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m by\u001b[0m\u001b[33m Google\u001b[0m\u001b[33m Quantum\u001b[0m\u001b[33m AI\u001b[0m\u001b[33m Lab\u001b[0m\u001b[33m (\u001b[0m\u001b[33mURL\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mIBM\u001b[0m\u001b[33m's\u001b[0m\u001b[33m \u001b[0m\u001b[33m127\u001b[0m\u001b[33m-q\u001b[0m\u001b[33mubit\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m by\u001b[0m\u001b[33m IBM\u001b[0m\u001b[33m Quantum\u001b[0m\u001b[33m (\u001b[0m\u001b[33mURL\u001b[0m\u001b[33m)\u001b[0m\u001b[97m\u001b[0m\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m IBM\u001b[0m\u001b[33m Quantum\u001b[0m\u001b[33m Experience\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mwww\u001b[0m\u001b[33m.ibm\u001b[0m\u001b[33m.com\u001b[0m\u001b[33m/\u001b[0m\u001b[33mquant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m-com\u001b[0m\u001b[33mput\u001b[0m\u001b[33ming\u001b[0m\u001b[33m/)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m Google\u001b[0m\u001b[33m's\u001b[0m\u001b[33m S\u001b[0m\u001b[33myc\u001b[0m\u001b[33mam\u001b[0m\u001b[33more\u001b[0m\u001b[33m processor\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33ms\u001b[0m\u001b[33mcai\u001b[0m\u001b[33m.st\u001b[0m\u001b[33manford\u001b[0m\u001b[33m.edu\u001b[0m\u001b[33m/~\u001b[0m\u001b[33mmw\u001b[0m\u001b[33mj\u001b[0m\u001b[33m/s\u001b[0m\u001b[33myc\u001b[0m\u001b[33mam\u001b[0m\u001b[33more\u001b[0m\u001b[33m.html\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m error\u001b[0m\u001b[33m correction\u001b[0m\u001b[33m with\u001b[0m\u001b[33m encoded\u001b[0m\u001b[33m cat\u001b[0m\u001b[33m codes\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mar\u001b[0m\u001b[33mxiv\u001b[0m\u001b[33m.org\u001b[0m\u001b[33m/\u001b[0m\u001b[33mabs\u001b[0m\u001b[33m/\u001b[0m\u001b[33m210\u001b[0m\u001b[33m4\u001b[0m\u001b[33m.\u001b[0m\u001b[33m045\u001b[0m\u001b[33m93\u001b[0m\u001b[33m)\n",
"\u001b[0m\u001b[33m-\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mQuant\u001b[0m\u001b[33mum\u001b[0m\u001b[33m simulation\u001b[0m\u001b[33m of\u001b[0m\u001b[33m many\u001b[0m\u001b[33m-body\u001b[0m\u001b[33m systems\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m (\u001b[0m\u001b[33mhttps\u001b[0m\u001b[33m://\u001b[0m\u001b[33mar\u001b[0m\u001b[33mxiv\u001b[0m\u001b[33m.org\u001b[0m\u001b[33m/\u001b[0m\u001b[33mabs\u001b[0m\u001b[33m/\u001b[0m\u001b[33m210\u001b[0m\u001b[33m2\u001b[0m\u001b[33m.\u001b[0m\u001b[33m081\u001b[0m\u001b[33m83\u001b[0m\u001b[33m)\u001b[0m\u001b[97m\u001b[0m\n",
"\u001b[30m\u001b[0m"
]
}
@ -129,12 +130,12 @@
" engine=\"brave\",\n",
" api_key=\"dummy_value\"#os.getenv(\"BRAVE_SEARCH_API_KEY\"),\n",
" )\n",
" \n",
"\n",
" models_response = client.models.list()\n",
" for model in models_response:\n",
" if model.identifier.endswith(\"Instruct\"):\n",
" model_name = model.llama_model\n",
" \n",
"\n",
"\n",
" return await create_tool_agent(\n",
" client=client,\n",
@ -194,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@ -211,25 +212,24 @@
"\u001b[0m\u001b[33m \u001b[0m\u001b[33m \"\u001b[0m\u001b[33mlocation\u001b[0m\u001b[33m\":\u001b[0m\u001b[33m \"\u001b[0m\u001b[33mSan\u001b[0m\u001b[33m Francisco\u001b[0m\u001b[33m\"\n",
"\u001b[0m\u001b[33m \u001b[0m\u001b[33m }\n",
"\u001b[0m\u001b[33m}\u001b[0m\u001b[97m\u001b[0m\n",
"tool_calls starting: ToolCall(arguments={'location': 'San Francisco'}, call_id='420a73c9-1f6b-4f98-8fef-a7b9d2feb753', tool_name='get_weather')\n",
"Using Location: San Francisco\n",
"\u001b[32mCustomTool> {\"temperature\": 72.5, \"conditions\": \"partly cloudy\", \"humidity\": 65.0}\u001b[0m\n",
"\n",
"Query: Tell me the weather in Tokyo tomorrow\n",
"--------------------------------------------------\n",
"\u001b[30m\u001b[0m\u001b[33minference> \u001b[0m\u001b[36m\u001b[0m\u001b[36m{\"\u001b[0m\u001b[36mtype\u001b[0m\u001b[36m\":\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mfunction\u001b[0m\u001b[36m\",\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mname\u001b[0m\u001b[36m\":\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mget\u001b[0m\u001b[36m_weather\u001b[0m\u001b[36m\",\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mparameters\u001b[0m\u001b[36m\":\u001b[0m\u001b[36m {\"\u001b[0m\u001b[36mlocation\u001b[0m\u001b[36m\":\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mTok\u001b[0m\u001b[36myo\u001b[0m\u001b[36m\",\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mdate\u001b[0m\u001b[36m\":\u001b[0m\u001b[36m \"\u001b[0m\u001b[36mtom\u001b[0m\u001b[36morrow\u001b[0m\u001b[36m\"}}\u001b[0m\u001b[97m\u001b[0m\n",
"tool_calls starting: ToolCall(arguments={'location': 'Tokyo', 'date': 'tomorrow'}, call_id='9f94b5f1-fa5a-492f-a81f-dcfaafc970f3', tool_name='get_weather')\n",
"Using Location: Tokyo\n",
"Using date: tomorrow\n"
"\u001b[32mCustomTool> {\"temperature\": 90.1, \"conditions\": \"sunny\", \"humidity\": 40.0}\u001b[0m\n"
]
}
],
"source": [
"from typing import TypedDict, Optional, Dict, Any\n",
"from datetime import datetime\n",
"\n",
"import json\n",
"from llama_stack_client.types.tool_param_definition_param import ToolParamDefinitionParam\n",
"from llama_stack_client.types import CompletionMessage\n",
"class WeatherTool:\n",
"from llama_stack_client.types import CompletionMessage,ToolResponseMessage\n",
"from llama_stack_client.lib.agents.custom_tool import CustomTool\n",
"\n",
"class WeatherTool(CustomTool):\n",
" \"\"\"Example custom tool for weather information.\"\"\"\n",
"\n",
" def get_name(self) -> str:\n",
@ -251,31 +251,43 @@
" required=False\n",
" )\n",
" }\n",
" async def run(self,messages):\n",
" for message in messages:\n",
" print(\"tool_calls starting: \", message.tool_calls[0])\n",
" return_dict = message.tool_calls[0].arguments\n",
" location = return_dict.get(\"location\", None)\n",
" date = return_dict.get(\"date\", None)\n",
" print(\"Using Location:\",location)\n",
" if date:\n",
" print(\"Using date:\",date)\n",
" return await self.run_impl(location,date)\n",
" \n",
" async def run(self, messages: List[CompletionMessage]) -> List[ToolResponseMessage]:\n",
" assert len(messages) == 1, \"Expected single message\"\n",
"\n",
" message = messages[0]\n",
"\n",
" tool_call = message.tool_calls[0]\n",
" # location = tool_call.arguments.get(\"location\", None)\n",
" # date = tool_call.arguments.get(\"date\", None)\n",
" try:\n",
" response = await self.run_impl(**tool_call.arguments)\n",
" response_str = json.dumps(response, ensure_ascii=False)\n",
" except Exception as e:\n",
" response_str = f\"Error when running tool: {e}\"\n",
"\n",
" message = ToolResponseMessage(\n",
" call_id=tool_call.call_id,\n",
" tool_name=tool_call.tool_name,\n",
" content=response_str,\n",
" role=\"ipython\",\n",
" )\n",
" return [message]\n",
"\n",
" async def run_impl(self, location: str, date: Optional[str] = None) -> Dict[str, Any]:\n",
" \"\"\"Simulate getting weather data (replace with actual API call).\"\"\"\n",
" # Mock implementation\n",
" return [CompletionMessage(\n",
" content=\"\"\"{\n",
" if date:\n",
" return {\n",
" \"temperature\": 90.1,\n",
" \"conditions\": \"sunny\",\n",
" \"humidity\": 40.0\n",
" }\n",
" return {\n",
" \"temperature\": 72.5,\n",
" \"conditions\": \"partly cloudy\",\n",
" \"humidity\": 65.0\n",
" }\"\"\",\n",
" role='assistant',\n",
" stop_reason='end_of_message',\n",
" tool_calls=[],\n",
" )],\n",
" \n",
" }\n",
"\n",
"\n",
"async def create_weather_agent(client: LlamaStackClient) -> Agent:\n",
" \"\"\"Create an agent with weather tool capability.\"\"\"\n",
@ -350,7 +362,7 @@
" messages=[{\"role\": \"user\", \"content\": query}],\n",
" session_id=session_id,\n",
" )\n",
" \n",
"\n",
" async for log in EventLogger().log(response):\n",
" log.print()\n",
"\n",