mirror of
				https://github.com/meta-llama/llama-stack.git
				synced 2025-10-25 09:05:37 +00:00 
			
		
		
		
	This PR updates the Conversation item related types and improves a couple critical parts of the implemenation: - it creates a streaming output item for the final assistant message output by the model. until now we only added content parts and included that message in the final response. - rewrites the conversation update code completely to account for items other than messages (tool calls, outputs, etc.) ## Test Plan Used the test script from https://github.com/llamastack/llama-stack-client-python/pull/281 for this ``` TEST_API_BASE_URL=http://localhost:8321/v1 \ pytest tests/integration/test_agent_turn_step_events.py::test_client_side_function_tool -xvs ```
		
			
				
	
	
		
			631 lines
		
	
	
	
		
			19 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
		
			Generated
		
	
	
			
		
		
	
	
			631 lines
		
	
	
	
		
			19 KiB
		
	
	
	
		
			JSON
		
	
	
	
	
		
			Generated
		
	
	
| {
 | |
|   "test_id": "tests/integration/responses/test_tool_responses.py::test_response_sequential_file_search[openai_client-txt=openai/gpt-4o:emb=Nomic-v1.5:dim=768]",
 | |
|   "request": {
 | |
|     "method": "POST",
 | |
|     "url": "https://api.openai.com/v1/v1/chat/completions",
 | |
|     "headers": {},
 | |
|     "body": {
 | |
|       "model": "gpt-4o",
 | |
|       "messages": [
 | |
|         {
 | |
|           "role": "user",
 | |
|           "content": "How many experts does the Llama 4 Maverick model have?"
 | |
|         },
 | |
|         {
 | |
|           "role": "assistant",
 | |
|           "content": "",
 | |
|           "tool_calls": [
 | |
|             {
 | |
|               "index": 0,
 | |
|               "id": "call_UVmJRK8x8PZSXaGMP8YkWUTN",
 | |
|               "type": "function",
 | |
|               "function": {
 | |
|                 "name": "knowledge_search",
 | |
|                 "arguments": "{\"query\":\"Llama 4 Maverick model number of experts\"}"
 | |
|               }
 | |
|             }
 | |
|           ]
 | |
|         },
 | |
|         {
 | |
|           "role": "tool",
 | |
|           "tool_call_id": "call_UVmJRK8x8PZSXaGMP8YkWUTN",
 | |
|           "content": [
 | |
|             {
 | |
|               "type": "text",
 | |
|               "text": "knowledge_search tool found 1 chunks:\nBEGIN of knowledge_search tool results.\n"
 | |
|             },
 | |
|             {
 | |
|               "type": "text",
 | |
|               "text": "[1] document_id: file-753491389399, score: 0.1388247736002883, attributes: {'filename': 'test_sequential_file_search.txt', 'document_id': 'file-753491389399', 'token_count': 19.0, 'metadata_token_count': 11.0} (cite as <|file-753491389399|>)\nThe Llama 4 Maverick model has 128 experts in its mixture of experts architecture.\n"
 | |
|             },
 | |
|             {
 | |
|               "type": "text",
 | |
|               "text": "END of knowledge_search tool results.\n"
 | |
|             },
 | |
|             {
 | |
|               "type": "text",
 | |
|               "text": "The above results were retrieved to help answer the user's query: \"Llama 4 Maverick model number of experts\". Use them as supporting information only in answering this query. Cite sources immediately at the end of sentences before punctuation, using `<|file-id|>` format (e.g., 'This is a fact <|file-Cn3MSNn72ENTiiq11Qda4A|>.'). Do not add extra punctuation. Use only the file IDs provided (do not invent new ones).\n"
 | |
|             }
 | |
|           ]
 | |
|         },
 | |
|         {
 | |
|           "role": "assistant",
 | |
|           "content": "The Llama 4 Maverick model has 128 experts in its mixture of experts architecture <|file-753491389399|>."
 | |
|         },
 | |
|         {
 | |
|           "role": "user",
 | |
|           "content": "Can you tell me more about the architecture?"
 | |
|         }
 | |
|       ],
 | |
|       "stream": true,
 | |
|       "stream_options": {
 | |
|         "include_usage": true
 | |
|       },
 | |
|       "tools": [
 | |
|         {
 | |
|           "type": "function",
 | |
|           "function": {
 | |
|             "name": "knowledge_search",
 | |
|             "description": "Search for information in a database.",
 | |
|             "parameters": {
 | |
|               "type": "object",
 | |
|               "properties": {
 | |
|                 "query": {
 | |
|                   "type": "string",
 | |
|                   "description": "The query to search for. Can be a natural language sentence or keywords."
 | |
|                 }
 | |
|               },
 | |
|               "required": [
 | |
|                 "query"
 | |
|               ]
 | |
|             }
 | |
|           }
 | |
|         }
 | |
|       ]
 | |
|     },
 | |
|     "endpoint": "/v1/chat/completions",
 | |
|     "model": "gpt-4o"
 | |
|   },
 | |
|   "response": {
 | |
|     "body": [
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": "assistant",
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": "call_5D3edO8yoUmeC523679kcOAC",
 | |
|                     "function": {
 | |
|                       "arguments": "",
 | |
|                       "name": "knowledge_search"
 | |
|                     },
 | |
|                     "type": "function"
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "LuVF"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "{\"",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "bOQ"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "query",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "r"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "\":\"",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "w"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "L",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "2VvL8"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "lama",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "hC"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": " ",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "h0ec0"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "4",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "TMpEz"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": " Maver",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": ""
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "ick",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "sy2"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": " model",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": ""
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": " architecture",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "Z5q4wUlBq"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": [
 | |
|                   {
 | |
|                     "index": 0,
 | |
|                     "id": null,
 | |
|                     "function": {
 | |
|                       "arguments": "\"}",
 | |
|                       "name": null
 | |
|                     },
 | |
|                     "type": null
 | |
|                   }
 | |
|                 ]
 | |
|               },
 | |
|               "finish_reason": null,
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "mkQ"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [
 | |
|             {
 | |
|               "delta": {
 | |
|                 "content": null,
 | |
|                 "function_call": null,
 | |
|                 "refusal": null,
 | |
|                 "role": null,
 | |
|                 "tool_calls": null
 | |
|               },
 | |
|               "finish_reason": "tool_calls",
 | |
|               "index": 0,
 | |
|               "logprobs": null
 | |
|             }
 | |
|           ],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": null,
 | |
|           "obfuscation": "Bd3u"
 | |
|         }
 | |
|       },
 | |
|       {
 | |
|         "__type__": "openai.types.chat.chat_completion_chunk.ChatCompletionChunk",
 | |
|         "__data__": {
 | |
|           "id": "rec-8ce76cb00986",
 | |
|           "choices": [],
 | |
|           "created": 0,
 | |
|           "model": "gpt-4o-2024-08-06",
 | |
|           "object": "chat.completion.chunk",
 | |
|           "service_tier": "default",
 | |
|           "system_fingerprint": "fp_f64f290af2",
 | |
|           "usage": {
 | |
|             "completion_tokens": 22,
 | |
|             "prompt_tokens": 377,
 | |
|             "total_tokens": 399,
 | |
|             "completion_tokens_details": {
 | |
|               "accepted_prediction_tokens": 0,
 | |
|               "audio_tokens": 0,
 | |
|               "reasoning_tokens": 0,
 | |
|               "rejected_prediction_tokens": 0
 | |
|             },
 | |
|             "prompt_tokens_details": {
 | |
|               "audio_tokens": 0,
 | |
|               "cached_tokens": 0
 | |
|             }
 | |
|           },
 | |
|           "obfuscation": "l98LrzJRFZh5w"
 | |
|         }
 | |
|       }
 | |
|     ],
 | |
|     "is_streaming": true
 | |
|   },
 | |
|   "id_normalization_mapping": {}
 | |
| }
 |