forked from phoenix-oss/llama-stack-mirror
# Summary: new Agent SDK API is added in https://github.com/meta-llama/llama-stack-client-python/pull/178 Update docs and test to reflect this. Closes https://github.com/meta-llama/llama-stack/issues/1365 # Test Plan: ```bash py.test -v -s --nbval-lax ./docs/getting_started.ipynb LLAMA_STACK_CONFIG=fireworks \ pytest -s -v tests/integration/agents/test_agents.py \ --safety-shield meta-llama/Llama-Guard-3-8B --text-model meta-llama/Llama-3.1-8B-Instruct ```
191 lines
18 KiB
Text
191 lines
18 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Agentic API 101\n",
|
|
"\n",
|
|
"This document talks about the Agentic APIs in Llama Stack. Before you begin, please ensure Llama Stack is installed and set up by following the [Getting Started Guide](https://llama-stack.readthedocs.io/en/latest/getting_started/index.html).\n",
|
|
"\n",
|
|
"Starting Llama 3.1 you can build agentic applications capable of:\n",
|
|
"\n",
|
|
"- breaking a task down and performing multi-step reasoning.\n",
|
|
"- using tools to perform some actions\n",
|
|
" - built-in: the model has built-in knowledge of tools like search or code interpreter\n",
|
|
" - zero-shot: the model can learn to call tools using previously unseen, in-context tool definitions\n",
|
|
"- providing system level safety protections using models like Llama Guard.\n",
|
|
"\n",
|
|
"An agentic app requires a few components:\n",
|
|
"- ability to run inference on the underlying Llama series of models\n",
|
|
"- ability to run safety checks using the Llama Guard series of models\n",
|
|
"- ability to execute tools, including a code execution environment, and loop using the model's multi-step reasoning process\n",
|
|
"\n",
|
|
"All of these components are now offered by a single Llama Stack Distribution. Llama Stack defines and standardizes these components and many others that are needed to make building Generative AI applications smoother. Various implementations of these APIs are then assembled together via a **Llama Stack Distribution**.\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Run Agent example\n",
|
|
"\n",
|
|
"Please check out examples with client SDKs to talk with the Llama Stack server in our [llama-stack-apps](https://github.com/meta-llama/llama-stack-apps) repo. \n",
|
|
"\n",
|
|
"In this tutorial, with the `Llama3.1-8B-Instruct` server running, we can use the following code to run a simple agent example:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Set up your connection parameters:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"HOST = \"localhost\" # Replace with your host\n",
|
|
"PORT = 5001 # Replace with your port\n",
|
|
"MODEL_NAME = \"meta-llama/Llama-3.2-3B-Instruct\"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"from dotenv import load_dotenv\n",
|
|
"\n",
|
|
"load_dotenv()\n",
|
|
"BRAVE_SEARCH_API_KEY = os.environ[\"BRAVE_SEARCH_API_KEY\"]\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Created session_id=5c4dc91a-5b8f-4adb-978b-986bad2ce777 for Agent(a7c4ae7a-2638-4e7f-9d4d-5f0644a1f418)\n",
|
|
"\u001b[30m\u001b[0m\u001b[33minference> \u001b[0m\u001b[36m\u001b[0m\u001b[36mbr\u001b[0m\u001b[36mave\u001b[0m\u001b[36m_search\u001b[0m\u001b[36m.call\u001b[0m\u001b[36m(query\u001b[0m\u001b[36m=\"\u001b[0m\u001b[36mtop\u001b[0m\u001b[36m \u001b[0m\u001b[36m3\u001b[0m\u001b[36m places\u001b[0m\u001b[36m to\u001b[0m\u001b[36m visit\u001b[0m\u001b[36m in\u001b[0m\u001b[36m Switzerland\u001b[0m\u001b[36m\")\u001b[0m\u001b[97m\u001b[0m\n",
|
|
"\u001b[32mtool_execution> Tool:brave_search Args:{'query': 'top 3 places to visit in Switzerland'}\u001b[0m\n",
|
|
"\u001b[32mtool_execution> Tool:brave_search Response:{\"query\": \"top 3 places to visit in Switzerland\", \"top_k\": [{\"title\": \"18 Best Places to Visit in Switzerland \\u2013 Touropia Travel\", \"url\": \"https://www.touropia.com/best-places-to-visit-in-switzerland/\", \"description\": \"I have visited Switzerland more than 5 times. I have visited several places of this beautiful country like <strong>Geneva, Zurich, Bern, Luserne, Laussane, Jungfrau, Interlaken Aust & West, Zermatt, Vevey, Lugano, Swiss Alps, Grindelwald</strong>, any several more.\", \"type\": \"search_result\"}, {\"title\": \"The 10 best places to visit in Switzerland | Expatica\", \"url\": \"https://www.expatica.com/ch/lifestyle/things-to-do/best-places-to-visit-in-switzerland-102301/\", \"description\": \"Get ready to explore vibrant cities and majestic landscapes.\", \"type\": \"search_result\"}, {\"title\": \"17 Best Places to Visit in Switzerland | U.S. News Travel\", \"url\": \"https://travel.usnews.com/rankings/best-places-to-visit-in-switzerland/\", \"description\": \"From tranquil lakes to ritzy ski resorts, this list of the Best <strong>Places</strong> <strong>to</strong> <strong>Visit</strong> <strong>in</strong> <strong>Switzerland</strong> is all you'll need to plan your Swiss vacation.\", \"type\": \"search_result\"}]}\u001b[0m\n",
|
|
"\u001b[35mshield_call> No Violation\u001b[0m\n",
|
|
"\u001b[33minference> \u001b[0m\u001b[33mBased\u001b[0m\u001b[33m on\u001b[0m\u001b[33m the\u001b[0m\u001b[33m search\u001b[0m\u001b[33m results\u001b[0m\u001b[33m,\u001b[0m\u001b[33m the\u001b[0m\u001b[33m top\u001b[0m\u001b[33m \u001b[0m\u001b[33m3\u001b[0m\u001b[33m places\u001b[0m\u001b[33m to\u001b[0m\u001b[33m visit\u001b[0m\u001b[33m in\u001b[0m\u001b[33m Switzerland\u001b[0m\u001b[33m are\u001b[0m\u001b[33m:\n",
|
|
"\n",
|
|
"\u001b[0m\u001b[33m1\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m\n",
|
|
"\u001b[0m\u001b[33m2\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Zurich\u001b[0m\u001b[33m\n",
|
|
"\u001b[0m\u001b[33m3\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Bern\u001b[0m\u001b[33m\n",
|
|
"\n",
|
|
"\u001b[0m\u001b[33mThese\u001b[0m\u001b[33m cities\u001b[0m\u001b[33m offer\u001b[0m\u001b[33m a\u001b[0m\u001b[33m mix\u001b[0m\u001b[33m of\u001b[0m\u001b[33m vibrant\u001b[0m\u001b[33m culture\u001b[0m\u001b[33m,\u001b[0m\u001b[33m stunning\u001b[0m\u001b[33m landscapes\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m exciting\u001b[0m\u001b[33m activities\u001b[0m\u001b[33m such\u001b[0m\u001b[33m as\u001b[0m\u001b[33m skiing\u001b[0m\u001b[33m and\u001b[0m\u001b[33m exploring\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Swiss\u001b[0m\u001b[33m Alps\u001b[0m\u001b[33m.\u001b[0m\u001b[33m Additionally\u001b[0m\u001b[33m,\u001b[0m\u001b[33m other\u001b[0m\u001b[33m popular\u001b[0m\u001b[33m destinations\u001b[0m\u001b[33m include\u001b[0m\u001b[33m L\u001b[0m\u001b[33muser\u001b[0m\u001b[33mne\u001b[0m\u001b[33m,\u001b[0m\u001b[33m La\u001b[0m\u001b[33muss\u001b[0m\u001b[33mane\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Jung\u001b[0m\u001b[33mfrau\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Inter\u001b[0m\u001b[33ml\u001b[0m\u001b[33maken\u001b[0m\u001b[33m Aust\u001b[0m\u001b[33m &\u001b[0m\u001b[33m West\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Z\u001b[0m\u001b[33merm\u001b[0m\u001b[33matt\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Ve\u001b[0m\u001b[33mvey\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Lug\u001b[0m\u001b[33mano\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Swiss\u001b[0m\u001b[33m Alps\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Gr\u001b[0m\u001b[33mind\u001b[0m\u001b[33mel\u001b[0m\u001b[33mwald\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m many\u001b[0m\u001b[33m more\u001b[0m\u001b[33m.\u001b[0m\u001b[97m\u001b[0m\n",
|
|
"\u001b[30m\u001b[0m\u001b[30m\u001b[0m\u001b[33minference> \u001b[0m\u001b[33mGene\u001b[0m\u001b[33mva\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Switzerland\u001b[0m\u001b[33m!\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m a\u001b[0m\u001b[33m global\u001b[0m\u001b[33m city\u001b[0m\u001b[33m located\u001b[0m\u001b[33m in\u001b[0m\u001b[33m the\u001b[0m\u001b[33m western\u001b[0m\u001b[33m part\u001b[0m\u001b[33m of\u001b[0m\u001b[33m Switzerland\u001b[0m\u001b[33m,\u001b[0m\u001b[33m on\u001b[0m\u001b[33m the\u001b[0m\u001b[33m shores\u001b[0m\u001b[33m of\u001b[0m\u001b[33m Lake\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m (\u001b[0m\u001b[33malso\u001b[0m\u001b[33m known\u001b[0m\u001b[33m as\u001b[0m\u001b[33m Lac\u001b[0m\u001b[33m L\u001b[0m\u001b[33mé\u001b[0m\u001b[33mman\u001b[0m\u001b[33m).\u001b[0m\u001b[33m Here\u001b[0m\u001b[33m are\u001b[0m\u001b[33m some\u001b[0m\u001b[33m things\u001b[0m\u001b[33m that\u001b[0m\u001b[33m make\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m special\u001b[0m\u001b[33m:\n",
|
|
"\n",
|
|
"\u001b[0m\u001b[33m1\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mInternational\u001b[0m\u001b[33m organizations\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m home\u001b[0m\u001b[33m to\u001b[0m\u001b[33m numerous\u001b[0m\u001b[33m international\u001b[0m\u001b[33m organizations\u001b[0m\u001b[33m,\u001b[0m\u001b[33m including\u001b[0m\u001b[33m the\u001b[0m\u001b[33m United\u001b[0m\u001b[33m Nations\u001b[0m\u001b[33m (\u001b[0m\u001b[33mUN\u001b[0m\u001b[33m),\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Red\u001b[0m\u001b[33m Cross\u001b[0m\u001b[33m and\u001b[0m\u001b[33m Red\u001b[0m\u001b[33m Crescent\u001b[0m\u001b[33m Movement\u001b[0m\u001b[33m,\u001b[0m\u001b[33m the\u001b[0m\u001b[33m World\u001b[0m\u001b[33m Trade\u001b[0m\u001b[33m Organization\u001b[0m\u001b[33m (\u001b[0m\u001b[33mW\u001b[0m\u001b[33mTO\u001b[0m\u001b[33m),\u001b[0m\u001b[33m and\u001b[0m\u001b[33m the\u001b[0m\u001b[33m International\u001b[0m\u001b[33m Committee\u001b[0m\u001b[33m of\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Red\u001b[0m\u001b[33m Cross\u001b[0m\u001b[33m (\u001b[0m\u001b[33mIC\u001b[0m\u001b[33mRC\u001b[0m\u001b[33m).\n",
|
|
"\u001b[0m\u001b[33m2\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mPeace\u001b[0m\u001b[33mful\u001b[0m\u001b[33m atmosphere\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m known\u001b[0m\u001b[33m for\u001b[0m\u001b[33m its\u001b[0m\u001b[33m tranquil\u001b[0m\u001b[33m atmosphere\u001b[0m\u001b[33m,\u001b[0m\u001b[33m making\u001b[0m\u001b[33m it\u001b[0m\u001b[33m a\u001b[0m\u001b[33m popular\u001b[0m\u001b[33m destination\u001b[0m\u001b[33m for\u001b[0m\u001b[33m diplomats\u001b[0m\u001b[33m,\u001b[0m\u001b[33m businesses\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m individuals\u001b[0m\u001b[33m seeking\u001b[0m\u001b[33m a\u001b[0m\u001b[33m peaceful\u001b[0m\u001b[33m environment\u001b[0m\u001b[33m.\n",
|
|
"\u001b[0m\u001b[33m3\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mC\u001b[0m\u001b[33multural\u001b[0m\u001b[33m events\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m hosts\u001b[0m\u001b[33m various\u001b[0m\u001b[33m cultural\u001b[0m\u001b[33m events\u001b[0m\u001b[33m throughout\u001b[0m\u001b[33m the\u001b[0m\u001b[33m year\u001b[0m\u001b[33m,\u001b[0m\u001b[33m such\u001b[0m\u001b[33m as\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m International\u001b[0m\u001b[33m Film\u001b[0m\u001b[33m Festival\u001b[0m\u001b[33m,\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m Art\u001b[0m\u001b[33m Fair\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Jazz\u001b[0m\u001b[33m à\u001b[0m\u001b[33m Gen\u001b[0m\u001b[33mève\u001b[0m\u001b[33m festival\u001b[0m\u001b[33m.\n",
|
|
"\u001b[0m\u001b[33m4\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mM\u001b[0m\u001b[33muse\u001b[0m\u001b[33mums\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m The\u001b[0m\u001b[33m city\u001b[0m\u001b[33m is\u001b[0m\u001b[33m home\u001b[0m\u001b[33m to\u001b[0m\u001b[33m several\u001b[0m\u001b[33m world\u001b[0m\u001b[33m-class\u001b[0m\u001b[33m museums\u001b[0m\u001b[33m,\u001b[0m\u001b[33m including\u001b[0m\u001b[33m the\u001b[0m\u001b[33m P\u001b[0m\u001b[33mate\u001b[0m\u001b[33mk\u001b[0m\u001b[33m Philippe\u001b[0m\u001b[33m Museum\u001b[0m\u001b[33m,\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Mus\u001b[0m\u001b[33mée\u001b[0m\u001b[33m d\u001b[0m\u001b[33m'\u001b[0m\u001b[33mArt\u001b[0m\u001b[33m et\u001b[0m\u001b[33m d\u001b[0m\u001b[33m'H\u001b[0m\u001b[33misto\u001b[0m\u001b[33mire\u001b[0m\u001b[33m (\u001b[0m\u001b[33mMA\u001b[0m\u001b[33mH\u001b[0m\u001b[33m),\u001b[0m\u001b[33m and\u001b[0m\u001b[33m the\u001b[0m\u001b[33m Pal\u001b[0m\u001b[33mais\u001b[0m\u001b[33m des\u001b[0m\u001b[33m Nations\u001b[0m\u001b[33m (\u001b[0m\u001b[33mUN\u001b[0m\u001b[33m Headquarters\u001b[0m\u001b[33m).\n",
|
|
"\u001b[0m\u001b[33m5\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mLake\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m situated\u001b[0m\u001b[33m on\u001b[0m\u001b[33m the\u001b[0m\u001b[33m shores\u001b[0m\u001b[33m of\u001b[0m\u001b[33m Lake\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m,\u001b[0m\u001b[33m offering\u001b[0m\u001b[33m stunning\u001b[0m\u001b[33m views\u001b[0m\u001b[33m and\u001b[0m\u001b[33m water\u001b[0m\u001b[33m sports\u001b[0m\u001b[33m activities\u001b[0m\u001b[33m like\u001b[0m\u001b[33m sailing\u001b[0m\u001b[33m,\u001b[0m\u001b[33m row\u001b[0m\u001b[33ming\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m paddle\u001b[0m\u001b[33mboarding\u001b[0m\u001b[33m.\n",
|
|
"\u001b[0m\u001b[33m6\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mLux\u001b[0m\u001b[33mury\u001b[0m\u001b[33m shopping\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m famous\u001b[0m\u001b[33m for\u001b[0m\u001b[33m its\u001b[0m\u001b[33m high\u001b[0m\u001b[33m-end\u001b[0m\u001b[33m bout\u001b[0m\u001b[33miques\u001b[0m\u001b[33m,\u001b[0m\u001b[33m designer\u001b[0m\u001b[33m brands\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m luxury\u001b[0m\u001b[33m goods\u001b[0m\u001b[33m,\u001b[0m\u001b[33m making\u001b[0m\u001b[33m it\u001b[0m\u001b[33m a\u001b[0m\u001b[33m shopper\u001b[0m\u001b[33m's\u001b[0m\u001b[33m paradise\u001b[0m\u001b[33m.\n",
|
|
"\u001b[0m\u001b[33m7\u001b[0m\u001b[33m.\u001b[0m\u001b[33m **\u001b[0m\u001b[33mDel\u001b[0m\u001b[33micious\u001b[0m\u001b[33m cuisine\u001b[0m\u001b[33m**:\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m offers\u001b[0m\u001b[33m a\u001b[0m\u001b[33m unique\u001b[0m\u001b[33m blend\u001b[0m\u001b[33m of\u001b[0m\u001b[33m French\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Swiss\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m Italian\u001b[0m\u001b[33m flavors\u001b[0m\u001b[33m,\u001b[0m\u001b[33m with\u001b[0m\u001b[33m popular\u001b[0m\u001b[33m dishes\u001b[0m\u001b[33m like\u001b[0m\u001b[33m fond\u001b[0m\u001b[33mue\u001b[0m\u001b[33m,\u001b[0m\u001b[33m rac\u001b[0m\u001b[33mlette\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m cro\u001b[0m\u001b[33miss\u001b[0m\u001b[33mants\u001b[0m\u001b[33m.\n",
|
|
"\n",
|
|
"\u001b[0m\u001b[33mOverall\u001b[0m\u001b[33m,\u001b[0m\u001b[33m Geneva\u001b[0m\u001b[33m is\u001b[0m\u001b[33m a\u001b[0m\u001b[33m beautiful\u001b[0m\u001b[33m and\u001b[0m\u001b[33m vibrant\u001b[0m\u001b[33m city\u001b[0m\u001b[33m that\u001b[0m\u001b[33m offers\u001b[0m\u001b[33m a\u001b[0m\u001b[33m unique\u001b[0m\u001b[33m combination\u001b[0m\u001b[33m of\u001b[0m\u001b[33m culture\u001b[0m\u001b[33m,\u001b[0m\u001b[33m history\u001b[0m\u001b[33m,\u001b[0m\u001b[33m and\u001b[0m\u001b[33m luxury\u001b[0m\u001b[33m,\u001b[0m\u001b[33m making\u001b[0m\u001b[33m it\u001b[0m\u001b[33m an\u001b[0m\u001b[33m excellent\u001b[0m\u001b[33m destination\u001b[0m\u001b[33m for\u001b[0m\u001b[33m tourists\u001b[0m\u001b[33m and\u001b[0m\u001b[33m business\u001b[0m\u001b[33m travelers\u001b[0m\u001b[33m alike\u001b[0m\u001b[33m.\u001b[0m\u001b[97m\u001b[0m\n",
|
|
"\u001b[30m\u001b[0m"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"from llama_stack_client import LlamaStackClient\n",
|
|
"from llama_stack_client.lib.agents.agent import Agent\n",
|
|
"from llama_stack_client.lib.agents.event_logger import EventLogger\n",
|
|
"\n",
|
|
"\n",
|
|
"async def agent_example():\n",
|
|
" client = LlamaStackClient(base_url=f\"http://{HOST}:{PORT}\")\n",
|
|
" agent = Agent(\n",
|
|
" client, \n",
|
|
" model=MODEL_NAME,\n",
|
|
" instructions=\"You are a helpful assistant! If you call builtin tools like brave search, follow the syntax brave_search.call(…)\",\n",
|
|
" sampling_params={\n",
|
|
" \"strategy\": {\n",
|
|
" \"type\": \"greedy\",\n",
|
|
" },\n",
|
|
" },\n",
|
|
" tools=[\n",
|
|
" {\n",
|
|
" \"type\": \"brave_search\",\n",
|
|
" \"engine\": \"brave\",\n",
|
|
" \"api_key\": BRAVE_SEARCH_API_KEY,\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" )\n",
|
|
" session_id = agent.create_session(\"test-session\")\n",
|
|
" print(f\"Created session_id={session_id} for Agent({agent.agent_id})\")\n",
|
|
"\n",
|
|
" user_prompts = [\n",
|
|
" \"I am planning a trip to Switzerland, what are the top 3 places to visit?\",\n",
|
|
" \"What is so special about #1?\",\n",
|
|
" ]\n",
|
|
"\n",
|
|
" for prompt in user_prompts:\n",
|
|
" response = agent.create_turn(\n",
|
|
" messages=[\n",
|
|
" {\n",
|
|
" \"role\": \"user\",\n",
|
|
" \"content\": prompt,\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" session_id=session_id,\n",
|
|
" )\n",
|
|
"\n",
|
|
" async for log in EventLogger().log(response):\n",
|
|
" log.print()\n",
|
|
"\n",
|
|
"\n",
|
|
"await agent_example()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"We have come a long way from getting started to understanding the internals of Llama-Stack! \n",
|
|
"\n",
|
|
"Thanks for joining us on this journey. If you have questions-please feel free to open an issue. Looking forward to what you build with Open Source AI!"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.15"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|