|
64 | 64 | " \"Want rollers too?\"\n", |
65 | 65 | " )\n", |
66 | 66 | " conversation_id = \"retail-session-002\"\n", |
| 67 | + " tool_call_id = \"call-17\"\n", |
| 68 | + " tool_arguments = {\"product_type\": \"paint\", \"finish\": \"satin\"}\n", |
| 69 | + " tool_result = {\n", |
| 70 | + " \"sku\": \"PAINT-FAST-221\",\n", |
| 71 | + " \"name\": \"Zava SwiftCoat Satin\",\n", |
| 72 | + " \"inventory\": 142\n", |
| 73 | + " }\n", |
| 74 | + " input_messages = [\n", |
| 75 | + " {\n", |
| 76 | + " \"role\": \"system\",\n", |
| 77 | + " \"parts\": [\n", |
| 78 | + " {\"type\": \"text\", \"content\": system_prompt}\n", |
| 79 | + " ],\n", |
| 80 | + " },\n", |
| 81 | + " {\n", |
| 82 | + " \"role\": \"user\",\n", |
| 83 | + " \"parts\": [\n", |
| 84 | + " {\"type\": \"text\", \"content\": customer_prompt}\n", |
| 85 | + " ],\n", |
| 86 | + " },\n", |
| 87 | + " {\n", |
| 88 | + " \"role\": \"assistant\",\n", |
| 89 | + " \"parts\": [\n", |
| 90 | + " {\n", |
| 91 | + " \"type\": \"tool_call\",\n", |
| 92 | + " \"id\": tool_call_id,\n", |
| 93 | + " \"name\": \"inventory_lookup\",\n", |
| 94 | + " \"arguments\": tool_arguments\n", |
| 95 | + " }\n", |
| 96 | + " ],\n", |
| 97 | + " },\n", |
| 98 | + " {\n", |
| 99 | + " \"role\": \"tool\",\n", |
| 100 | + " \"parts\": [\n", |
| 101 | + " {\n", |
| 102 | + " \"type\": \"tool_call_response\",\n", |
| 103 | + " \"id\": tool_call_id,\n", |
| 104 | + " \"result\": tool_result\n", |
| 105 | + " }\n", |
| 106 | + " ],\n", |
| 107 | + " },\n", |
| 108 | + " ]\n", |
| 109 | + " output_messages = [\n", |
| 110 | + " {\n", |
| 111 | + " \"role\": \"assistant\",\n", |
| 112 | + " \"parts\": [\n", |
| 113 | + " {\"type\": \"text\", \"content\": agent_reply}\n", |
| 114 | + " ],\n", |
| 115 | + " \"finish_reason\": \"stop\"\n", |
| 116 | + " }\n", |
| 117 | + " ]\n", |
67 | 118 | "\n", |
68 | 119 | " with tracer.start_as_current_span(\"invoke_agent cora-retail-agent\", kind=SpanKind.CLIENT) as span:\n", |
69 | 120 | " span.set_attribute(\"gen_ai.provider.name\", \"azure.ai.inference\")\n", |
|
82 | 133 | " span.set_attribute(\"gen_ai.usage.output_tokens\", 41)\n", |
83 | 134 | " span.set_attribute(\"gen_ai.conversation.id\", conversation_id)\n", |
84 | 135 | " span.set_attribute(\"gen_ai.system_instructions\", system_prompt)\n", |
85 | | - " span.set_attribute(\"gen_ai.input.messages\", json.dumps([\n", |
86 | | - " {\"role\": \"system\", \"content\": system_prompt},\n", |
87 | | - " {\"role\": \"user\", \"content\": customer_prompt}\n", |
88 | | - " ], ensure_ascii=False))\n", |
89 | | - " span.set_attribute(\"gen_ai.output.messages\", json.dumps([\n", |
90 | | - " {\"role\": \"assistant\", \"content\": agent_reply}\n", |
91 | | - " ], ensure_ascii=False))\n", |
| 136 | + " span.set_attribute(\"gen_ai.input.messages\", json.dumps(input_messages, ensure_ascii=False))\n", |
| 137 | + " span.set_attribute(\"gen_ai.output.messages\", json.dumps(output_messages, ensure_ascii=False))\n", |
92 | 138 | " span.set_attribute(\"server.address\", \"cora-agents.eastus2.inference.ai.azure.com\")\n", |
93 | 139 | " span.set_attribute(\"server.port\", 443)\n", |
94 | 140 | "\n", |
95 | 141 | " with tracer.start_as_current_span(\"execute_tool inventory_lookup\", kind=SpanKind.INTERNAL) as tool_span:\n", |
96 | 142 | " tool_span.set_attribute(\"gen_ai.operation.name\", \"execute_tool\")\n", |
97 | 143 | " tool_span.set_attribute(\"gen_ai.tool.name\", \"inventory_lookup\")\n", |
98 | 144 | " tool_span.set_attribute(\"gen_ai.tool.type\", \"function\")\n", |
99 | | - " tool_span.set_attribute(\"gen_ai.tool.call.id\", \"call-17\")\n", |
100 | | - " tool_span.set_attribute(\"gen_ai.tool.call.arguments\", json.dumps({\n", |
101 | | - " \"product_type\": \"paint\",\n", |
102 | | - " \"finish\": \"satin\"\n", |
103 | | - " }))\n", |
104 | | - " tool_span.set_attribute(\"gen_ai.tool.call.result\", json.dumps({\n", |
105 | | - " \"sku\": \"PAINT-FAST-221\",\n", |
106 | | - " \"name\": \"Zava SwiftCoat Satin\",\n", |
107 | | - " \"inventory\": 142\n", |
108 | | - " }))\n", |
| 145 | + " tool_span.set_attribute(\"gen_ai.tool.call.id\", tool_call_id)\n", |
| 146 | + " tool_span.set_attribute(\"gen_ai.tool.call.arguments\", json.dumps(tool_arguments))\n", |
| 147 | + " tool_span.set_attribute(\"gen_ai.tool.call.result\", json.dumps(tool_result))\n", |
109 | 148 | "\n", |
110 | 149 | "record_agent_interaction()\n", |
111 | 150 | "print(\"Interaction recorded.\")" |
|
0 commit comments