From ec62020a201ab118721ac30e1178c764ddd3a741 Mon Sep 17 00:00:00 2001 From: Xi Yan Date: Wed, 26 Feb 2025 15:16:31 -0800 Subject: [PATCH] retrieve session / turn / steps --- .../Llama_Stack_Agents_Monitoring.ipynb | 469 ++++++++++-------- .../agents/meta_reference/agent_instance.py | 8 +- .../inline/agents/meta_reference/agents.py | 25 +- .../agents/meta_reference/persistence.py | 9 +- 4 files changed, 274 insertions(+), 237 deletions(-) diff --git a/docs/notebooks/Llama_Stack_Agents_Monitoring.ipynb b/docs/notebooks/Llama_Stack_Agents_Monitoring.ipynb index aadac6b2b..01395400d 100644 --- a/docs/notebooks/Llama_Stack_Agents_Monitoring.ipynb +++ b/docs/notebooks/Llama_Stack_Agents_Monitoring.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -61,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -72,30 +72,30 @@ "│ │ UserMessage(content='Who received the IEEE Frank Rosenblatt Award in 2010?', role='user', context=None)\n", "],\n", "output_message=CompletionMessage(\n", - "│ │ content='The recipient of the IEEE Frank Rosenblatt Award in 2010 was Dr. Ronald Fagin.',\n", + "│ │ content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n", "│ │ role='assistant',\n", "│ │ stop_reason='end_of_turn',\n", "│ │ tool_calls=[]\n", "),\n", - "session_id='3a15bc56-f736-4126-8137-a5cb87406225',\n", - "started_at=datetime.datetime(2025, 2, 26, 12, 48, 15, 774381, tzinfo=TzInfo(-08:00)),\n", + "session_id='558ddd4a-32f9-4455-b13f-a365dc8b04f7',\n", + "started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 917982, tzinfo=TzInfo(-08:00)),\n", "steps=[\n", "│ │ InferenceStep(\n", "│ │ │ api_model_response=CompletionMessage(\n", - "│ │ │ │ content='The recipient of the IEEE Frank Rosenblatt Award in 2010 was Dr. Ronald Fagin.',\n", + "│ │ │ │ content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n", "│ │ │ │ role='assistant',\n", "│ │ │ │ stop_reason='end_of_turn',\n", "│ │ │ │ tool_calls=[]\n", "│ │ │ ),\n", - "│ │ │ step_id='6c660138-574e-49a9-9f8c-552ccce874fc',\n", + "│ │ │ step_id='896d9ebd-5a26-4831-aff4-48bc136b26fc',\n", "│ │ │ step_type='inference',\n", - "│ │ │ turn_id='7f07185b-66a0-4701-b965-5ff74793c2c4',\n", - "│ │ │ completed_at=datetime.datetime(2025, 2, 26, 12, 48, 16, 689502, tzinfo=TzInfo(-08:00)),\n", - "│ │ │ started_at=datetime.datetime(2025, 2, 26, 12, 48, 15, 786046, tzinfo=TzInfo(-08:00))\n", + "│ │ │ turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n", + "│ │ │ completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 861070, tzinfo=TzInfo(-08:00)),\n", + "│ │ │ started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 929704, tzinfo=TzInfo(-08:00))\n", "│ │ )\n", "],\n", - "turn_id='7f07185b-66a0-4701-b965-5ff74793c2c4',\n", - "completed_at=datetime.datetime(2025, 2, 26, 12, 48, 16, 702110, tzinfo=TzInfo(-08:00)),\n", + "turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n", + "completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 875151, tzinfo=TzInfo(-08:00)),\n", "output_attachments=[]\n", ")\n", "\n" @@ -106,192 +106,30 @@ "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mUserMessage\u001b[0m\u001b[1m(\u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'Who received the IEEE Frank Rosenblatt Award in 2010?'\u001b[0m, \u001b[33mrole\u001b[0m=\u001b[32m'user'\u001b[0m, \u001b[33mcontext\u001b[0m=\u001b[3;35mNone\u001b[0m\u001b[1m)\u001b[0m\n", "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", "\u001b[2;32m│ \u001b[0m\u001b[33moutput_message\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The recipient of the IEEE Frank Rosenblatt Award in 2010 was Dr. Ronald Fagin.'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", "\u001b[2;32m│ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", "\u001b[2;32m│ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", "\u001b[2;32m│ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'3a15bc56-f736-4126-8137-a5cb87406225'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m774381\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'558ddd4a-32f9-4455-b13f-a365dc8b04f7'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m917982\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", "\u001b[2;32m│ \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n", "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The recipient of the IEEE Frank Rosenblatt Award in 2010 was Dr. Ronald Fagin.'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'6c660138-574e-49a9-9f8c-552ccce874fc'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'896d9ebd-5a26-4831-aff4-48bc136b26fc'\u001b[0m,\n", "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'7f07185b-66a0-4701-b965-5ff74793c2c4'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m16\u001b[0m, \u001b[1;36m689502\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m786046\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m861070\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m929704\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'7f07185b-66a0-4701-b965-5ff74793c2c4'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m16\u001b[0m, \u001b[1;36m702110\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33moutput_attachments\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[1m)\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Turn(\n",
-       "input_messages=[\n",
-       "│   │   UserMessage(\n",
-       "│   │   │   content=\"Who was awarded the Oceanography Society's Jerlov Award in 2018?\",\n",
-       "│   │   │   role='user',\n",
-       "│   │   │   context=None\n",
-       "│   │   )\n",
-       "],\n",
-       "output_message=CompletionMessage(\n",
-       "│   │   content=\"The Oceanography Society's Jerlov Award for 2018 was awarded to Dr. Emmanuel Boss.\",\n",
-       "│   │   role='assistant',\n",
-       "│   │   stop_reason='end_of_turn',\n",
-       "│   │   tool_calls=[]\n",
-       "),\n",
-       "session_id='d0dfe88d-f75c-448c-892a-067aff1c1b72',\n",
-       "started_at=datetime.datetime(2025, 2, 26, 12, 48, 16, 740702, tzinfo=TzInfo(-08:00)),\n",
-       "steps=[\n",
-       "│   │   InferenceStep(\n",
-       "│   │   │   api_model_response=CompletionMessage(\n",
-       "│   │   │   │   content=\"The Oceanography Society's Jerlov Award for 2018 was awarded to Dr. Emmanuel Boss.\",\n",
-       "│   │   │   │   role='assistant',\n",
-       "│   │   │   │   stop_reason='end_of_turn',\n",
-       "│   │   │   │   tool_calls=[]\n",
-       "│   │   │   ),\n",
-       "│   │   │   step_id='c9c7ede1-94af-4f28-9068-8817dd675392',\n",
-       "│   │   │   step_type='inference',\n",
-       "│   │   │   turn_id='f701695e-389c-4078-9a4f-228479cf4d6a',\n",
-       "│   │   │   completed_at=datetime.datetime(2025, 2, 26, 12, 48, 17, 505687, tzinfo=TzInfo(-08:00)),\n",
-       "│   │   │   started_at=datetime.datetime(2025, 2, 26, 12, 48, 16, 752172, tzinfo=TzInfo(-08:00))\n",
-       "│   │   )\n",
-       "],\n",
-       "turn_id='f701695e-389c-4078-9a4f-228479cf4d6a',\n",
-       "completed_at=datetime.datetime(2025, 2, 26, 12, 48, 17, 516772, tzinfo=TzInfo(-08:00)),\n",
-       "output_attachments=[]\n",
-       ")\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[1;35mTurn\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[33minput_messages\u001b[0m=\u001b[1m[\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mUserMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"Who\u001b[0m\u001b[32m was awarded the Oceanography Society's Jerlov Award in 2018?\"\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'user'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcontext\u001b[0m=\u001b[3;35mNone\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33moutput_message\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"The\u001b[0m\u001b[32m Oceanography Society's Jerlov Award for 2018 was awarded to Dr. Emmanuel Boss.\"\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'd0dfe88d-f75c-448c-892a-067aff1c1b72'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m16\u001b[0m, \u001b[1;36m740702\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"The\u001b[0m\u001b[32m Oceanography Society's Jerlov Award for 2018 was awarded to Dr. Emmanuel Boss.\"\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'c9c7ede1-94af-4f28-9068-8817dd675392'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'f701695e-389c-4078-9a4f-228479cf4d6a'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m505687\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m16\u001b[0m, \u001b[1;36m752172\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'f701695e-389c-4078-9a4f-228479cf4d6a'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m516772\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33moutput_attachments\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[1m)\u001b[0m\n" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Turn(\n",
-       "input_messages=[\n",
-       "│   │   UserMessage(\n",
-       "│   │   │   content=\"What's the name of the women's liberal arts college in Cambridge, Massachusetts?\",\n",
-       "│   │   │   role='user',\n",
-       "│   │   │   context=None\n",
-       "│   │   )\n",
-       "],\n",
-       "output_message=CompletionMessage(\n",
-       "│   │   content=\"The women's liberal arts college in Cambridge, Massachusetts is Radcliffe College. However, it's important to note that Radcliffe College merged with Harvard University in 1999 and is now known as the Radcliffe Institute for Advanced Study at Harvard University. The institute still offers programs and resources for women, but it is no longer an independent college.\",\n",
-       "│   │   role='assistant',\n",
-       "│   │   stop_reason='end_of_turn',\n",
-       "│   │   tool_calls=[]\n",
-       "),\n",
-       "session_id='2424c5ca-afb2-4cc4-a5f5-f7ce0ec473d5',\n",
-       "started_at=datetime.datetime(2025, 2, 26, 12, 48, 17, 560298, tzinfo=TzInfo(-08:00)),\n",
-       "steps=[\n",
-       "│   │   InferenceStep(\n",
-       "│   │   │   api_model_response=CompletionMessage(\n",
-       "│   │   │   │   content=\"The women's liberal arts college in Cambridge, Massachusetts is Radcliffe College. However, it's important to note that Radcliffe College merged with Harvard University in 1999 and is now known as the Radcliffe Institute for Advanced Study at Harvard University. The institute still offers programs and resources for women, but it is no longer an independent college.\",\n",
-       "│   │   │   │   role='assistant',\n",
-       "│   │   │   │   stop_reason='end_of_turn',\n",
-       "│   │   │   │   tool_calls=[]\n",
-       "│   │   │   ),\n",
-       "│   │   │   step_id='2cbf44bc-d836-4449-99f6-a5fe72c2d8a0',\n",
-       "│   │   │   step_type='inference',\n",
-       "│   │   │   turn_id='0b4040e7-7aa6-4f86-a072-31333ffa29be',\n",
-       "│   │   │   completed_at=datetime.datetime(2025, 2, 26, 12, 48, 19, 269112, tzinfo=TzInfo(-08:00)),\n",
-       "│   │   │   started_at=datetime.datetime(2025, 2, 26, 12, 48, 17, 571880, tzinfo=TzInfo(-08:00))\n",
-       "│   │   )\n",
-       "],\n",
-       "turn_id='0b4040e7-7aa6-4f86-a072-31333ffa29be',\n",
-       "completed_at=datetime.datetime(2025, 2, 26, 12, 48, 19, 282118, tzinfo=TzInfo(-08:00)),\n",
-       "output_attachments=[]\n",
-       ")\n",
-       "
\n" - ], - "text/plain": [ - "\u001b[1;35mTurn\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[33minput_messages\u001b[0m=\u001b[1m[\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mUserMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"What\u001b[0m\u001b[32m's the name of the women's liberal arts college in Cambridge, Massachusetts?\"\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'user'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcontext\u001b[0m=\u001b[3;35mNone\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33moutput_message\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"The\u001b[0m\u001b[32m women's liberal arts college in Cambridge, Massachusetts is Radcliffe College. However, it's important to note that Radcliffe College merged with Harvard University in 1999 and is now known as the Radcliffe Institute for Advanced Study at Harvard University. The institute still offers programs and resources for women, but it is no longer an independent college.\"\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'2424c5ca-afb2-4cc4-a5f5-f7ce0ec473d5'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m560298\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m\"The\u001b[0m\u001b[32m women's liberal arts college in Cambridge, Massachusetts is Radcliffe College. However, it's important to note that Radcliffe College merged with Harvard University in 1999 and is now known as the Radcliffe Institute for Advanced Study at Harvard University. The institute still offers programs and resources for women, but it is no longer an independent college.\"\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", - "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'2cbf44bc-d836-4449-99f6-a5fe72c2d8a0'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'0b4040e7-7aa6-4f86-a072-31333ffa29be'\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m269112\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", - "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m17\u001b[0m, \u001b[1;36m571880\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", - "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'0b4040e7-7aa6-4f86-a072-31333ffa29be'\u001b[0m,\n", - "\u001b[2;32m│ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m12\u001b[0m, \u001b[1;36m48\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m282118\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m875151\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", "\u001b[2;32m│ \u001b[0m\u001b[33moutput_attachments\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", "\u001b[1m)\u001b[0m\n" ] @@ -313,7 +151,7 @@ "questions = []\n", "answers = []\n", "for idx, x in enumerate(ds[\"train\"]):\n", - " if idx >= 3:\n", + " if idx >= 1:\n", " break\n", " questions.append(x[\"input_query\"])\n", " answers.append(x[\"expected_answer\"])\n", @@ -343,27 +181,217 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 70, "metadata": {}, "outputs": [ { - "ename": "InternalServerError", - "evalue": "Error code: 500 - {'detail': 'Internal server error: An unexpected error occurred.'}", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mInternalServerError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[53], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m agent_id \u001b[38;5;241m=\u001b[39m agent\u001b[38;5;241m.\u001b[39magent_id\n\u001b[1;32m 5\u001b[0m \u001b[38;5;66;03m# print(session_ids)\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43magents\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mretrieve\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43msession_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43md1cb76fb-cd59-4dd9-afe5-0ce7ede630a9\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43magent_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43magent_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(response)\n\u001b[1;32m 11\u001b[0m \u001b[38;5;66;03m# client.agents.turn.retrieve(\u001b[39;00m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m# session_id=\"89459cef-7494-4a37-8278-59343b6174a3\",\u001b[39;00m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;66;03m# agent_id=agent_id,\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 22\u001b[0m \n\u001b[1;32m 23\u001b[0m \u001b[38;5;66;03m# pprint(session2turns)\u001b[39;00m\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/resources/agents/session.py:110\u001b[0m, in \u001b[0;36mSessionResource.retrieve\u001b[0;34m(self, session_id, agent_id, turn_ids, extra_headers, extra_query, extra_body, timeout)\u001b[0m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m session_id:\n\u001b[1;32m 109\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpected a non-empty value for `session_id` but received \u001b[39m\u001b[38;5;132;01m{\u001b[39;00msession_id\u001b[38;5;132;01m!r}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 110\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 111\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/v1/agents/\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43magent_id\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m/session/\u001b[39;49m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43msession_id\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 112\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 113\u001b[0m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 114\u001b[0m \u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 115\u001b[0m \u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 116\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 117\u001b[0m \u001b[43m \u001b[49m\u001b[43mquery\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mturn_ids\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mturn_ids\u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msession_retrieve_params\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSessionRetrieveParams\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 118\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 119\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mSession\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 120\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1219\u001b[0m, in \u001b[0;36mSyncAPIClient.get\u001b[0;34m(self, path, cast_to, options, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1216\u001b[0m opts \u001b[38;5;241m=\u001b[39m FinalRequestOptions\u001b[38;5;241m.\u001b[39mconstruct(method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mget\u001b[39m\u001b[38;5;124m\"\u001b[39m, url\u001b[38;5;241m=\u001b[39mpath, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39moptions)\n\u001b[1;32m 1217\u001b[0m \u001b[38;5;66;03m# cast is required because mypy complains about returning Any even though\u001b[39;00m\n\u001b[1;32m 1218\u001b[0m \u001b[38;5;66;03m# it understands the type variables\u001b[39;00m\n\u001b[0;32m-> 1219\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:965\u001b[0m, in \u001b[0;36mSyncAPIClient.request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 962\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 963\u001b[0m retries_taken \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[0;32m--> 965\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 966\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 967\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 968\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 969\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 970\u001b[0m \u001b[43m \u001b[49m\u001b[43mretries_taken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretries_taken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 971\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1053\u001b[0m, in \u001b[0;36mSyncAPIClient._request\u001b[0;34m(self, cast_to, options, retries_taken, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1051\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m remaining_retries \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_should_retry(err\u001b[38;5;241m.\u001b[39mresponse):\n\u001b[1;32m 1052\u001b[0m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mclose()\n\u001b[0;32m-> 1053\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_retry_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1054\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1055\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1056\u001b[0m \u001b[43m \u001b[49m\u001b[43mretries_taken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretries_taken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1057\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1058\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1059\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1060\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1062\u001b[0m \u001b[38;5;66;03m# If the response is streamed then we need to explicitly read the response\u001b[39;00m\n\u001b[1;32m 1063\u001b[0m \u001b[38;5;66;03m# to completion before attempting to access the response text.\u001b[39;00m\n\u001b[1;32m 1064\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mis_closed:\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1102\u001b[0m, in \u001b[0;36mSyncAPIClient._retry_request\u001b[0;34m(self, options, cast_to, retries_taken, response_headers, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[38;5;66;03m# In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a\u001b[39;00m\n\u001b[1;32m 1099\u001b[0m \u001b[38;5;66;03m# different thread if necessary.\u001b[39;00m\n\u001b[1;32m 1100\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(timeout)\n\u001b[0;32m-> 1102\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1103\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1104\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1105\u001b[0m \u001b[43m \u001b[49m\u001b[43mretries_taken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretries_taken\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1106\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1107\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1053\u001b[0m, in \u001b[0;36mSyncAPIClient._request\u001b[0;34m(self, cast_to, options, retries_taken, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1051\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m remaining_retries \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_should_retry(err\u001b[38;5;241m.\u001b[39mresponse):\n\u001b[1;32m 1052\u001b[0m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mclose()\n\u001b[0;32m-> 1053\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_retry_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1054\u001b[0m \u001b[43m \u001b[49m\u001b[43minput_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1055\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1056\u001b[0m \u001b[43m \u001b[49m\u001b[43mretries_taken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretries_taken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1057\u001b[0m \u001b[43m \u001b[49m\u001b[43mresponse_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mresponse\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1058\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1059\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1060\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1062\u001b[0m \u001b[38;5;66;03m# If the response is streamed then we need to explicitly read the response\u001b[39;00m\n\u001b[1;32m 1063\u001b[0m \u001b[38;5;66;03m# to completion before attempting to access the response text.\u001b[39;00m\n\u001b[1;32m 1064\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mis_closed:\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1102\u001b[0m, in \u001b[0;36mSyncAPIClient._retry_request\u001b[0;34m(self, options, cast_to, retries_taken, response_headers, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1098\u001b[0m \u001b[38;5;66;03m# In a synchronous context we are blocking the entire thread. Up to the library user to run the client in a\u001b[39;00m\n\u001b[1;32m 1099\u001b[0m \u001b[38;5;66;03m# different thread if necessary.\u001b[39;00m\n\u001b[1;32m 1100\u001b[0m time\u001b[38;5;241m.\u001b[39msleep(timeout)\n\u001b[0;32m-> 1102\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1103\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1104\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1105\u001b[0m \u001b[43m \u001b[49m\u001b[43mretries_taken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretries_taken\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1106\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1107\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1108\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/Desktop/meta-llama/llama-stack-client-python/src/llama_stack_client/_base_client.py:1068\u001b[0m, in \u001b[0;36mSyncAPIClient._request\u001b[0;34m(self, cast_to, options, retries_taken, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1065\u001b[0m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mread()\n\u001b[1;32m 1067\u001b[0m log\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRe-raising status error\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m-> 1068\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_status_error_from_response(err\u001b[38;5;241m.\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1070\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_process_response(\n\u001b[1;32m 1071\u001b[0m cast_to\u001b[38;5;241m=\u001b[39mcast_to,\n\u001b[1;32m 1072\u001b[0m options\u001b[38;5;241m=\u001b[39moptions,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1076\u001b[0m retries_taken\u001b[38;5;241m=\u001b[39mretries_taken,\n\u001b[1;32m 1077\u001b[0m )\n", - "\u001b[0;31mInternalServerError\u001b[0m: Error code: 500 - {'detail': 'Internal server error: An unexpected error occurred.'}" - ] + "data": { + "text/html": [ + "
Session(\n",
+       "session_id='558ddd4a-32f9-4455-b13f-a365dc8b04f7',\n",
+       "session_name='260253b6c81a4e2595b3f57e69e54c01',\n",
+       "started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 900529),\n",
+       "turns=[\n",
+       "│   │   Turn(\n",
+       "│   │   │   input_messages=[\n",
+       "│   │   │   │   UserMessage(\n",
+       "│   │   │   │   │   content='Who received the IEEE Frank Rosenblatt Award in 2010?',\n",
+       "│   │   │   │   │   role='user',\n",
+       "│   │   │   │   │   context=None\n",
+       "│   │   │   │   )\n",
+       "│   │   │   ],\n",
+       "│   │   │   output_message=CompletionMessage(\n",
+       "│   │   │   │   content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n",
+       "│   │   │   │   role='assistant',\n",
+       "│   │   │   │   stop_reason='end_of_turn',\n",
+       "│   │   │   │   tool_calls=[]\n",
+       "│   │   │   ),\n",
+       "│   │   │   session_id='558ddd4a-32f9-4455-b13f-a365dc8b04f7',\n",
+       "│   │   │   started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 917982, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))),\n",
+       "│   │   │   steps=[\n",
+       "│   │   │   │   InferenceStep(\n",
+       "│   │   │   │   │   api_model_response=CompletionMessage(\n",
+       "│   │   │   │   │   │   content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n",
+       "│   │   │   │   │   │   role='assistant',\n",
+       "│   │   │   │   │   │   stop_reason='end_of_turn',\n",
+       "│   │   │   │   │   │   tool_calls=[]\n",
+       "│   │   │   │   │   ),\n",
+       "│   │   │   │   │   step_id='896d9ebd-5a26-4831-aff4-48bc136b26fc',\n",
+       "│   │   │   │   │   step_type='inference',\n",
+       "│   │   │   │   │   turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n",
+       "│   │   │   │   │   completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 861070, tzinfo=TzInfo(-08:00)),\n",
+       "│   │   │   │   │   started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 929704, tzinfo=TzInfo(-08:00))\n",
+       "│   │   │   │   )\n",
+       "│   │   │   ],\n",
+       "│   │   │   turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n",
+       "│   │   │   completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 875151, tzinfo=TzInfo(-08:00)),\n",
+       "│   │   │   output_attachments=[]\n",
+       "│   │   )\n",
+       "]\n",
+       ")\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1;35mSession\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'558ddd4a-32f9-4455-b13f-a365dc8b04f7'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33msession_name\u001b[0m=\u001b[32m'260253b6c81a4e2595b3f57e69e54c01'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m900529\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mturns\u001b[0m=\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mTurn\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33minput_messages\u001b[0m=\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[1;35mUserMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'Who received the IEEE Frank Rosenblatt Award in 2010?'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'user'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mcontext\u001b[0m=\u001b[3;35mNone\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m]\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33moutput_message\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'558ddd4a-32f9-4455-b13f-a365dc8b04f7'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m917982\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.timezone\u001b[0m\u001b[1m(\u001b[0m\u001b[1;35mdatetime.timedelta\u001b[0m\u001b[1m(\u001b[0m\u001b[33mdays\u001b[0m=\u001b[1;36m-1\u001b[0m, \u001b[33mseconds\u001b[0m=\u001b[1;36m57600\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'896d9ebd-5a26-4831-aff4-48bc136b26fc'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m861070\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m929704\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m]\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m875151\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33moutput_attachments\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[1m)\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Turn(\n",
+       "input_messages=[\n",
+       "│   │   UserMessage(content='Who received the IEEE Frank Rosenblatt Award in 2010?', role='user', context=None)\n",
+       "],\n",
+       "output_message=CompletionMessage(\n",
+       "│   │   content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n",
+       "│   │   role='assistant',\n",
+       "│   │   stop_reason='end_of_turn',\n",
+       "│   │   tool_calls=[]\n",
+       "),\n",
+       "session_id='558ddd4a-32f9-4455-b13f-a365dc8b04f7',\n",
+       "started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 917982, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600))),\n",
+       "steps=[\n",
+       "│   │   InferenceStep(\n",
+       "│   │   │   api_model_response=CompletionMessage(\n",
+       "│   │   │   │   content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n",
+       "│   │   │   │   role='assistant',\n",
+       "│   │   │   │   stop_reason='end_of_turn',\n",
+       "│   │   │   │   tool_calls=[]\n",
+       "│   │   │   ),\n",
+       "│   │   │   step_id='896d9ebd-5a26-4831-aff4-48bc136b26fc',\n",
+       "│   │   │   step_type='inference',\n",
+       "│   │   │   turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n",
+       "│   │   │   completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 861070, tzinfo=TzInfo(-08:00)),\n",
+       "│   │   │   started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 929704, tzinfo=TzInfo(-08:00))\n",
+       "│   │   )\n",
+       "],\n",
+       "turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n",
+       "completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 875151, tzinfo=TzInfo(-08:00)),\n",
+       "output_attachments=[]\n",
+       ")\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1;35mTurn\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[33minput_messages\u001b[0m=\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mUserMessage\u001b[0m\u001b[1m(\u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'Who received the IEEE Frank Rosenblatt Award in 2010?'\u001b[0m, \u001b[33mrole\u001b[0m=\u001b[32m'user'\u001b[0m, \u001b[33mcontext\u001b[0m=\u001b[3;35mNone\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33moutput_message\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33msession_id\u001b[0m=\u001b[32m'558ddd4a-32f9-4455-b13f-a365dc8b04f7'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m917982\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.timezone\u001b[0m\u001b[1m(\u001b[0m\u001b[1;35mdatetime.timedelta\u001b[0m\u001b[1m(\u001b[0m\u001b[33mdays\u001b[0m=\u001b[1;36m-1\u001b[0m, \u001b[33mseconds\u001b[0m=\u001b[1;36m57600\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33msteps\u001b[0m=\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", + "\u001b[2;32m│ │ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'896d9ebd-5a26-4831-aff4-48bc136b26fc'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m861070\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m929704\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m]\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m875151\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[33moutput_attachments\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[1m)\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
StepRetrieveResponse(\n",
+       "step=InferenceStep(\n",
+       "│   │   api_model_response=CompletionMessage(\n",
+       "│   │   │   content='The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.',\n",
+       "│   │   │   role='assistant',\n",
+       "│   │   │   stop_reason='end_of_turn',\n",
+       "│   │   │   tool_calls=[]\n",
+       "│   │   ),\n",
+       "│   │   step_id='896d9ebd-5a26-4831-aff4-48bc136b26fc',\n",
+       "│   │   step_type='inference',\n",
+       "│   │   turn_id='dcb9c5f1-36c9-4928-b13f-a6e9478a940b',\n",
+       "│   │   completed_at=datetime.datetime(2025, 2, 26, 15, 15, 19, 861070, tzinfo=TzInfo(-08:00)),\n",
+       "│   │   started_at=datetime.datetime(2025, 2, 26, 15, 15, 15, 929704, tzinfo=TzInfo(-08:00))\n",
+       ")\n",
+       ")\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1;35mStepRetrieveResponse\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[33mstep\u001b[0m=\u001b[1;35mInferenceStep\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mapi_model_response\u001b[0m=\u001b[1;35mCompletionMessage\u001b[0m\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mcontent\u001b[0m=\u001b[32m'The IEEE Frank Rosenblatt Award was given to Tomaso Poggio in 2010.'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mrole\u001b[0m=\u001b[32m'assistant'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mstop_reason\u001b[0m=\u001b[32m'end_of_turn'\u001b[0m,\n", + "\u001b[2;32m│ │ │ \u001b[0m\u001b[33mtool_calls\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mstep_id\u001b[0m=\u001b[32m'896d9ebd-5a26-4831-aff4-48bc136b26fc'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mstep_type\u001b[0m=\u001b[32m'inference'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mturn_id\u001b[0m=\u001b[32m'dcb9c5f1-36c9-4928-b13f-a6e9478a940b'\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mcompleted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m19\u001b[0m, \u001b[1;36m861070\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[33mstarted_at\u001b[0m=\u001b[1;35mdatetime\u001b[0m\u001b[1;35m.datetime\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m2025\u001b[0m, \u001b[1;36m2\u001b[0m, \u001b[1;36m26\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m15\u001b[0m, \u001b[1;36m929704\u001b[0m, \u001b[33mtzinfo\u001b[0m=\u001b[1;35mTzInfo\u001b[0m\u001b[1m(\u001b[0m\u001b[1;36m-08\u001b[0m:\u001b[1;36m00\u001b[0m\u001b[1m)\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[1m)\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -371,25 +399,26 @@ "session_ids = agent.sessions\n", "agent_id = agent.agent_id\n", "\n", - "# print(session_ids)\n", - "response = client.agents.session.retrieve(\n", - " session_id=\"d1cb76fb-cd59-4dd9-afe5-0ce7ede630a9\",\n", + "session_response = client.agents.session.retrieve(\n", + " session_id=session_ids[0],\n", " agent_id=agent_id,\n", ")\n", - "print(response)\n", - "# client.agents.turn.retrieve(\n", - "# session_id=\"89459cef-7494-4a37-8278-59343b6174a3\",\n", - "# agent_id=agent_id,\n", - "# turn_id=\"f1e09cd5-a2af-483b-9dfa-cc374528bcd7\",\n", - "# )\n", - "# session2turns = {}\n", - "# for session_id in session_ids:\n", - "# session2turns[session_id] = client.agents.session.retrieve(\n", - "# session_id=session_id,\n", - "# agent_id=agent_id,\n", - "# )\n", + "pprint(session_response)\n", "\n", - "# pprint(session2turns)" + "turn_response = client.agents.turn.retrieve(\n", + " session_id=session_ids[0],\n", + " agent_id=agent_id,\n", + " turn_id=session_response.turns[0].turn_id,\n", + ")\n", + "pprint(turn_response)\n", + "\n", + "step_response = client.agents.steps.retrieve(\n", + " session_id=session_ids[0],\n", + " agent_id=agent_id,\n", + " turn_id=session_response.turns[0].turn_id,\n", + " step_id=turn_response.steps[0].step_id,\n", + ")\n", + "pprint(step_response)" ] }, { diff --git a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py index b17179463..6873d945d 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agent_instance.py +++ b/llama_stack/providers/inline/agents/meta_reference/agent_instance.py @@ -61,7 +61,12 @@ from llama_stack.apis.inference import ( UserMessage, ) from llama_stack.apis.safety import Safety -from llama_stack.apis.tools import RAGDocument, ToolGroups, ToolInvocationResult, ToolRuntime +from llama_stack.apis.tools import ( + RAGDocument, + ToolGroups, + ToolInvocationResult, + ToolRuntime, +) from llama_stack.apis.vector_io import VectorIO from llama_stack.models.llama.datatypes import ( BuiltinTool, @@ -172,6 +177,7 @@ class ChatAgent(ShieldRunnerMixin): assert request.stream is True, "Non-streaming not supported" session_info = await self.storage.get_session_info(request.session_id) + print("SESSION INFO", session_info) if session_info is None: raise ValueError(f"Session {request.session_id} not found") diff --git a/llama_stack/providers/inline/agents/meta_reference/agents.py b/llama_stack/providers/inline/agents/meta_reference/agents.py index d8edb1de1..b5eb12c49 100644 --- a/llama_stack/providers/inline/agents/meta_reference/agents.py +++ b/llama_stack/providers/inline/agents/meta_reference/agents.py @@ -194,22 +194,16 @@ class MetaReferenceAgentsImpl(Agents): yield event async def get_agents_turn(self, agent_id: str, session_id: str, turn_id: str) -> Turn: - pass - # turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}") - # turn = json.loads(turn) - # turn = Turn(**turn) - # return turn + agent = await self.get_agent(agent_id) + turn = await agent.storage.get_session_turn(session_id, turn_id) + return turn async def get_agents_step(self, agent_id: str, session_id: str, turn_id: str, step_id: str) -> AgentStepResponse: - pass - # turn = await self.persistence_store.get(f"session:{agent_id}:{session_id}:{turn_id}") - # turn = json.loads(turn) - # turn = Turn(**turn) - # steps = turn.steps - # for step in steps: - # if step.step_id == step_id: - # return AgentStepResponse(step=step) - # raise ValueError(f"Provided step_id {step_id} could not be found") + turn = await self.get_agents_turn(agent_id, session_id, turn_id) + for step in turn.steps: + if step.step_id == step_id: + return AgentStepResponse(step=step) + raise ValueError(f"Provided step_id {step_id} could not be found") async def get_agents_session( self, @@ -219,7 +213,8 @@ class MetaReferenceAgentsImpl(Agents): ) -> Session: agent = await self.get_agent(agent_id) session_info = await agent.storage.get_session_info(session_id) - print(session_info) + if session_info is None: + raise ValueError(f"Session {session_id} not found") turns = await agent.storage.get_session_turns(session_id) if turn_ids: turns = [turn for turn in turns if turn.turn_id in turn_ids] diff --git a/llama_stack/providers/inline/agents/meta_reference/persistence.py b/llama_stack/providers/inline/agents/meta_reference/persistence.py index 94b7cbf42..9a2663567 100644 --- a/llama_stack/providers/inline/agents/meta_reference/persistence.py +++ b/llama_stack/providers/inline/agents/meta_reference/persistence.py @@ -32,7 +32,6 @@ class AgentPersistence: self.kvstore = kvstore async def create_session(self, name: str) -> str: - print("CREATE SESSION PERSISTANCE", name) session_id = str(uuid.uuid4()) session_info = AgentSessionInfo( session_id=session_id, @@ -87,6 +86,14 @@ class AgentPersistence: turns.sort(key=lambda x: (x.completed_at or datetime.min)) return turns + async def get_session_turn(self, session_id: str, turn_id: str) -> Optional[Turn]: + value = await self.kvstore.get( + key=f"session:{self.agent_id}:{session_id}:{turn_id}", + ) + if not value: + return None + return Turn(**json.loads(value)) + async def set_in_progress_tool_call_step(self, session_id: str, turn_id: str, step: ToolExecutionStep): await self.kvstore.set( key=f"in_progress_tool_call_step:{self.agent_id}:{session_id}:{turn_id}",