|
54 | 54 | "outputs": [], |
55 | 55 | "source": [ |
56 | 56 | "def record_agent_interaction():\n", |
57 | | - " system_prompt = (\"You are Cora, a polite, factual, and helpful Zava retail assistant. \" |
58 | | - "\"Answer with concise, markdown-friendly responses.\")\n", |
| 57 | + " system_prompt = (\n", |
| 58 | + " \"You are Cora, a polite, factual, and helpful Zava retail assistant. \"\n", |
| 59 | + " \"Answer with concise, markdown-friendly responses.\"\n", |
| 60 | + " )\n", |
59 | 61 | " customer_prompt = \"Do you have a satin finish paint that dries fast?\"\n", |
60 | | - " agent_reply = (\"⚡ Absolutely! Zava SwiftCoat Satin at $32 dries in 30 minutes. \" |
61 | | - "\"Want rollers too?\")\n", |
| 62 | + " agent_reply = (\n", |
| 63 | + " \"⚡ Absolutely! Zava SwiftCoat Satin at $32 dries in 30 minutes. \"\n", |
| 64 | + " \"Want rollers too?\"\n", |
| 65 | + " )\n", |
| 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 | + " tool_definitions = [\n", |
| 75 | + " {\n", |
| 76 | + " \"type\": \"function\",\n", |
| 77 | + " \"name\": \"inventory_lookup\",\n", |
| 78 | + " \"description\": \"Fetches inventory details for a specific product category and finish.\",\n", |
| 79 | + " \"parameters\": {\n", |
| 80 | + " \"type\": \"object\",\n", |
| 81 | + " \"properties\": {\n", |
| 82 | + " \"product_type\": {\n", |
| 83 | + " \"type\": \"string\",\n", |
| 84 | + " \"description\": \"Product category name to search.\"\n", |
| 85 | + " },\n", |
| 86 | + " \"finish\": {\n", |
| 87 | + " \"type\": \"string\",\n", |
| 88 | + " \"description\": \"Desired paint finish (e.g., satin, matte).\"\n", |
| 89 | + " }\n", |
| 90 | + " },\n", |
| 91 | + " \"required\": [\"product_type\"]\n", |
| 92 | + " }\n", |
| 93 | + " }\n", |
| 94 | + " ]\n", |
| 95 | + " input_messages = [\n", |
| 96 | + " {\n", |
| 97 | + " \"role\": \"system\",\n", |
| 98 | + " \"parts\": [\n", |
| 99 | + " {\"type\": \"text\", \"content\": system_prompt}\n", |
| 100 | + " ],\n", |
| 101 | + " },\n", |
| 102 | + " {\n", |
| 103 | + " \"role\": \"user\",\n", |
| 104 | + " \"parts\": [\n", |
| 105 | + " {\"type\": \"text\", \"content\": customer_prompt}\n", |
| 106 | + " ],\n", |
| 107 | + " },\n", |
| 108 | + " {\n", |
| 109 | + " \"role\": \"assistant\",\n", |
| 110 | + " \"parts\": [\n", |
| 111 | + " {\n", |
| 112 | + " \"type\": \"tool_call\",\n", |
| 113 | + " \"id\": tool_call_id,\n", |
| 114 | + " \"name\": \"inventory_lookup\",\n", |
| 115 | + " \"arguments\": tool_arguments\n", |
| 116 | + " }\n", |
| 117 | + " ],\n", |
| 118 | + " },\n", |
| 119 | + " {\n", |
| 120 | + " \"role\": \"tool\",\n", |
| 121 | + " \"parts\": [\n", |
| 122 | + " {\n", |
| 123 | + " \"type\": \"tool_call_response\",\n", |
| 124 | + " \"id\": tool_call_id,\n", |
| 125 | + " \"result\": tool_result\n", |
| 126 | + " }\n", |
| 127 | + " ],\n", |
| 128 | + " },\n", |
| 129 | + " ]\n", |
| 130 | + " output_messages = [\n", |
| 131 | + " {\n", |
| 132 | + " \"role\": \"assistant\",\n", |
| 133 | + " \"parts\": [\n", |
| 134 | + " {\"type\": \"text\", \"content\": agent_reply}\n", |
| 135 | + " ],\n", |
| 136 | + " \"finish_reason\": \"stop\"\n", |
| 137 | + " }\n", |
| 138 | + " ]\n", |
62 | 139 | "\n", |
63 | 140 | " with tracer.start_as_current_span(\"invoke_agent cora-retail-agent\", kind=SpanKind.CLIENT) as span:\n", |
64 | 141 | " span.set_attribute(\"gen_ai.provider.name\", \"azure.ai.inference\")\n", |
65 | 142 | " span.set_attribute(\"gen_ai.operation.name\", \"invoke_agent\")\n", |
66 | 143 | " span.set_attribute(\"gen_ai.agent.name\", \"cora-retail-agent\")\n", |
| 144 | + " span.set_attribute(\"gen_ai.agent.id\", \"agents/cora-retail-agent\")\n", |
| 145 | + " span.set_attribute(\"gen_ai.agent.description\", \"Cora retail assistant for Zava DIY customers.\")\n", |
67 | 146 | " span.set_attribute(\"gen_ai.request.model\", \"gpt-4o-mini\")\n", |
68 | 147 | " span.set_attribute(\"gen_ai.request.max_tokens\", 256)\n", |
69 | 148 | " span.set_attribute(\"gen_ai.request.temperature\", 0.3)\n", |
|
73 | 152 | " span.set_attribute(\"gen_ai.response.id\", \"resp-31f1\")\n", |
74 | 153 | " span.set_attribute(\"gen_ai.usage.input_tokens\", 98)\n", |
75 | 154 | " span.set_attribute(\"gen_ai.usage.output_tokens\", 41)\n", |
76 | | - " span.set_attribute(\"gen_ai.input.messages\", json.dumps([\n", |
77 | | - " {\"role\": \"system\", \"content\": system_prompt},\n", |
78 | | - " {\"role\": \"user\", \"content\": customer_prompt}\n", |
79 | | - " ], ensure_ascii=False))\n", |
80 | | - " span.set_attribute(\"gen_ai.output.messages\", json.dumps([\n", |
81 | | - " {\"role\": \"assistant\", \"content\": agent_reply}\n", |
82 | | - " ], ensure_ascii=False))\n", |
| 155 | + " span.set_attribute(\"gen_ai.conversation.id\", conversation_id)\n", |
| 156 | + " span.set_attribute(\"gen_ai.system_instructions\", system_prompt)\n", |
| 157 | + " span.set_attribute(\"gen_ai.tool.definitions\", json.dumps(tool_definitions, ensure_ascii=False))\n", |
| 158 | + " span.set_attribute(\"gen_ai.input.messages\", json.dumps(input_messages, ensure_ascii=False))\n", |
| 159 | + " span.set_attribute(\"gen_ai.output.messages\", json.dumps(output_messages, ensure_ascii=False))\n", |
83 | 160 | " span.set_attribute(\"server.address\", \"cora-agents.eastus2.inference.ai.azure.com\")\n", |
84 | 161 | " span.set_attribute(\"server.port\", 443)\n", |
85 | 162 | "\n", |
86 | 163 | " with tracer.start_as_current_span(\"execute_tool inventory_lookup\", kind=SpanKind.INTERNAL) as tool_span:\n", |
87 | 164 | " tool_span.set_attribute(\"gen_ai.operation.name\", \"execute_tool\")\n", |
88 | 165 | " tool_span.set_attribute(\"gen_ai.tool.name\", \"inventory_lookup\")\n", |
89 | 166 | " tool_span.set_attribute(\"gen_ai.tool.type\", \"function\")\n", |
90 | | - " tool_span.set_attribute(\"gen_ai.tool.call.id\", \"call-17\")\n", |
91 | | - " tool_span.set_attribute(\"gen_ai.tool.call.arguments\", json.dumps({\n", |
92 | | - " \"product_type\": \"paint\",\n", |
93 | | - " \"finish\": \"satin\"\n", |
94 | | - " }))\n", |
95 | | - " tool_span.set_attribute(\"gen_ai.tool.call.result\", json.dumps({\n", |
96 | | - " \"sku\": \"PAINT-FAST-221\",\n", |
97 | | - " \"name\": \"Zava SwiftCoat Satin\",\n", |
98 | | - " \"inventory\": 142\n", |
99 | | - " }))\n", |
| 167 | + " tool_span.set_attribute(\"gen_ai.tool.call.id\", tool_call_id)\n", |
| 168 | + " tool_span.set_attribute(\"gen_ai.tool.call.arguments\", json.dumps(tool_arguments))\n", |
| 169 | + " tool_span.set_attribute(\"gen_ai.tool.call.result\", json.dumps(tool_result))\n", |
100 | 170 | "\n", |
101 | 171 | "record_agent_interaction()\n", |
102 | 172 | "print(\"Interaction recorded.\")" |
|
0 commit comments