
{"id":124,"date":"2026-10-07T15:40:57","date_gmt":"2026-10-07T15:40:57","guid":{"rendered":"https:\/\/roboticsmaestro.com\/ai\/?p=124"},"modified":"2026-10-07T15:41:55","modified_gmt":"2026-10-07T15:41:55","slug":"124","status":"publish","type":"post","link":"https:\/\/roboticsmaestro.com\/ai\/blog\/2026\/10\/07\/124\/","title":{"rendered":"Azure AI foundry-conversation-memory-cosmosDB-blob"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>extend the persistent memory + conversation lifecycle system<\/strong> so it can integrate directly with an <strong>Azure AI Foundry Agent<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This means your <strong>multi-turn conversation memory<\/strong>, <strong>file state tracking<\/strong>, and <strong>cached\/non-cached container logic<\/strong> will be available to an Azure AI Foundry Agent for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Context injection<\/strong> into the agent\u2019s reasoning.<\/li>\n\n\n\n<li><strong>Tool orchestration<\/strong> (e.g., search, indexing, analytics).<\/li>\n\n\n\n<li><strong>Lifecycle-aware responses<\/strong> (knowing which conversations are completed vs in-progress).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Integration Goals<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Expose conversation + file state memory<\/strong> to Azure AI Foundry Agent via an API endpoint.<\/li>\n\n\n\n<li><strong>Allow the agent to query Cosmos DB<\/strong> for:\n<ul class=\"wp-block-list\">\n<li>Conversations linked to <code>non-cached-container<\/code> files.<\/li>\n\n\n\n<li>Completed conversations.<\/li>\n\n\n\n<li>Tool usage history.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Enable the agent to update conversation state<\/strong> when it processes files or uses tools.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Architecture<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">Copy code<code>Azure Function (Memory + Sync)\n    &#x2195;\nCosmos DB (Persistent Memory)\n    &#x2195;\nAzure AI Foundry Agent\n    &#x2195;\nTools (Azure Search, Blob Storage, MCP)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 1 \u2014 API Endpoint for Agent<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ll expose a REST API from the Azure Function so the Azure AI Foundry Agent can call it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">PythonCopy code<code>from flask import Flask, request, jsonify\n\napp = Flask(__name__)\n\n@app.route(\"\/agent\/memory\/conversations\", methods=[\"GET\"])\ndef get_conversations_for_agent():\n    \"\"\"Return conversations and file states for Azure AI Foundry Agent.\"\"\"\n    status_filter = request.args.get(\"status\")  # optional: 'completed' or 'in-progress'\n    try:\n        query = \"SELECT * FROM c WHERE c.type = 'conversation'\"\n        if status_filter:\n            query += f\" AND c.status = '{status_filter}'\"\n\n        conversations = list(cosmos_container.query_items(\n            query=query,\n            enable_cross_partition_query=True\n        ))\n        return jsonify(conversations), 200\n    except Exception as e:\n        logging.error(f\"Error fetching conversations for agent: {e}\")\n        return jsonify({\"error\": str(e)}), 500\n\n@app.route(\"\/agent\/memory\/files\", methods=[\"GET\"])\ndef get_files_for_agent():\n    \"\"\"Return file states for Azure AI Foundry Agent.\"\"\"\n    container_type = request.args.get(\"containerType\")  # optional: 'cached-container' or 'non-cached-container'\n    try:\n        query = \"SELECT * FROM c WHERE c.type = 'file_state'\"\n        if container_type:\n            query += f\" AND c.containerType = '{container_type}'\"\n\n        files = list(cosmos_container.query_items(\n            query=query,\n            enable_cross_partition_query=True\n        ))\n        return jsonify(files), 200\n    except Exception as e:\n        logging.error(f\"Error fetching files for agent: {e}\")\n        return jsonify({\"error\": str(e)}), 500\n\n@app.route(\"\/agent\/memory\/update\", methods=[\"POST\"])\ndef update_conversation_from_agent():\n    \"\"\"Allow Azure AI Foundry Agent to update conversation state.\"\"\"\n    data = request.json\n    doc_id = data.get(\"doc_id\")\n    status = data.get(\"status\")\n    summary = data.get(\"summary\")\n    try:\n        items = list(cosmos_container.query_items(\n            query=\"SELECT * FROM c WHERE c.id = @id AND c.type = 'conversation'\",\n            parameters=[{\"name\": \"@id\", \"value\": doc_id}],\n            enable_cross_partition_query=True\n        ))\n        if not items:\n            return jsonify({\"error\": \"Conversation not found\"}), 404\n\n        convo = items[0]\n        if status:\n            convo[\"status\"] = status\n        if summary:\n            convo[\"summary\"] = summary\n        cosmos_container.upsert_item(convo)\n        return jsonify({\"message\": \"Conversation updated\"}), 200\n    except Exception as e:\n        logging.error(f\"Error updating conversation from agent: {e}\")\n        return jsonify({\"error\": str(e)}), 500\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 2 \u2014 Azure AI Foundry Agent Tool Definition<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Azure AI Foundry, you can define a <strong>custom tool<\/strong> that calls these endpoints.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example tool definition in the agent\u2019s config:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">JsonCopy code<code>{\n  \"name\": \"ConversationMemoryTool\",\n  \"description\": \"Fetch and update conversation memory from Cosmos DB\",\n  \"endpoint\": \"https:\/\/&lt;your-function-app&gt;.azurewebsites.net\/agent\/memory\/conversations\",\n  \"methods\": [\n    {\n      \"name\": \"get_conversations\",\n      \"description\": \"Retrieve conversations with optional status filter\",\n      \"parameters\": {\n        \"status\": {\n          \"type\": \"string\",\n          \"description\": \"Filter by conversation status (completed or in-progress)\"\n        }\n      }\n    },\n    {\n      \"name\": \"get_files\",\n      \"description\": \"Retrieve file states with optional containerType filter\",\n      \"parameters\": {\n        \"containerType\": {\n          \"type\": \"string\",\n          \"description\": \"Filter by container type (cached-container or non-cached-container)\"\n        }\n      }\n    },\n    {\n      \"name\": \"update_conversation\",\n      \"description\": \"Update conversation status or summary\",\n      \"parameters\": {\n        \"doc_id\": { \"type\": \"string\" },\n        \"status\": { \"type\": \"string\" },\n        \"summary\": { \"type\": \"string\" }\n      }\n    }\n  ]\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 3 \u2014 Agent Workflow<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the Azure AI Foundry Agent runs:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Fetch conversations<\/strong>:PythonCopy code<code>GET \/agent\/memory\/conversations?status=in-progress<\/code><\/li>\n\n\n\n<li><strong>Fetch non-cached files<\/strong>:PythonCopy code<code>GET \/agent\/memory\/files?containerType=non-cached-container<\/code><\/li>\n\n\n\n<li><strong>Process files<\/strong> (e.g., run indexing, summarization).<\/li>\n\n\n\n<li><strong>Update conversation status<\/strong>:PythonCopy code<code>POST \/agent\/memory\/update { \"doc_id\": \"session_2026-10-06T12:30:00Z\", \"status\": \"completed\", \"summary\": \"All linked files processed and indexed.\" }<\/code><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Benefits<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Direct integration<\/strong> \u2014 Azure AI Foundry Agent can query and update memory in real-time.<\/li>\n\n\n\n<li><strong>Tool orchestration<\/strong> \u2014 Agent can decide which files to process based on conversation state.<\/li>\n\n\n\n<li><strong>Lifecycle awareness<\/strong> \u2014 Agent knows which conversations are completed vs pending.<\/li>\n\n\n\n<li><strong>Persistent context<\/strong> \u2014 Agent can recall multi-turn history and tool usage.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you want, I can <strong>extend this further<\/strong> so that the Azure AI Foundry Agent can also <strong>trigger the sync process<\/strong> directly via a tool call \u2014 meaning it can initiate file processing and indexing without manual intervention.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">=====================================================================<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>extend the persistent memory + conversation lifecycle system so it can integrate directly with an Azure AI Foundry Agent. This means your multi-turn conversation memory, file state tracking, and cached\/non-cached container logic will be available to an Azure AI Foundry Agent for: Integration Goals Architecture Copy codeAzure Function (Memory + Sync) &#x2195; Cosmos DB (Persistent [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_regular_price":[],"currency_symbol":[],"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-124","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"post_slider_layout_featured_media_urls":{"thumbnail":"","post_slider_layout_landscape_large":"","post_slider_layout_portrait_large":"","post_slider_layout_square_large":"","post_slider_layout_landscape":"","post_slider_layout_portrait":"","post_slider_layout_square":"","full":""},"_links":{"self":[{"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/posts\/124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":2,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/posts\/124\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roboticsmaestro.com\/ai\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}