Skip to content

Add competition entry doc + fix Cosmos DB parameterized queries#2

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/vscode1772540622743
Draft

Add competition entry doc + fix Cosmos DB parameterized queries#2
Copilot wants to merge 2 commits intomainfrom
copilot/vscode1772540622743

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

Adds a COMPETITION.md answering the three Agentic AI Competition questions (what/how/why) for the predictive maintenance multi-agent workflow built in the workshop. Also fixes two SQL injection vulnerabilities in CosmosDbService where skill names and part numbers were interpolated directly into Cosmos DB query strings.

Changes

COMPETITION.md (new)

Concise, humanised answers grounded in the workshop implementation:

  • What it does — five-agent sequential pipeline from sensor anomaly to scheduled work order + parts order
  • How it decides — each agent grounded in real data (telemetry thresholds, Foundry IQ knowledge base, deterministic fault→skills/parts mappings, live Cosmos DB queries); LLM handles reasoning, data handles facts
  • Why it's valuable — compresses hours of manual coordination to seconds without replacing the technician

CosmosDbService.cs — parameterized queries

Replaced string-interpolated query values with QueryDefinition.WithParameter() to eliminate injection risk:

// Before — skill/part values injected directly into query string
.Select(s => $"ARRAY_CONTAINS(c.skills, '{s}')")

// After — parameterized
var paramNames = requiredSkills.Select((_, i) => $"@skill{i}").ToList();
var query = new QueryDefinition($"SELECT * FROM c WHERE ... ({skillsFilter})");
for (var i = 0; i < requiredSkills.Count; i++)
    query = query.WithParameter($"@skill{i}", requiredSkills[i]);

Same pattern applied to the partNumber IN (...) query in GetPartsInventoryAsync.

Original prompt

Based on today´s workshop help me answer these questions in neutral tone, concise and precise language. Do not overexplain. Humanise language.

Agentic AI Competition: best idea for AI Agent

  1. What does it do?
  2. How does it decide what to do?
  3. Why is this valuable?
    sensitive):
    {
    "MachineId": string,
    "FaultType": string,
    "RootCause": string,
    "Severity": string,
    "DetectedAt": string, // ISO 8601 date-time, e.g. "2026-01-16T12:34:56Z"
    "Metadata": { string: any }
    }

Field rules:

  • MachineId: the machine identifier from the input (e.g. "machine-001").
  • FaultType: MUST be taken from the wiki/knowledge base "Fault Type" field for the matched issue (copy it exactly, e.g. "mixing_temperature_excessive"). Do not invent new fault types.
  • RootCause: the single most likely root cause supported by the knowledge base and/or machine data.
  • Severity: one of "Low", "Medium", "High", "Critical", or "Unknown".
  • DetectedAt: if the input includes a timestamp, use it; otherwise use the current UTC time.
  • Metadata: include supporting details used for the decision (e.g. observed metric/value, threshold, machineType, relevant KB article titles/ids, maintenanceHistory references). Do not include secrets/keys.
    • Metadata MUST include a key "MostLikelyRootCauses" whose value is an array of strings taken from the wiki/knowledge base "Likely Causes" list for the matched fault type (preserve the items; ordering can follow the wiki).

Grounding rules (IMPORTANT):

  • You must never answer from your own knowledge under any circumstances.

  • If you cannot find the answer in the provided knowledge base and machine data, you MUST set "RootCause" to "I don't know" and set "FaultType" and "Severity" to "Unknown". In this case, set "Metadata" to {"MostLikelyRootCauses": []}.
    """,

              tools=[
    
                  MCPTool(
                      server_label="machine-data",
                      server_url=machine_data_mcp_endpoint,
                      require_approval="never",
                      project_connection_id="machine-data-connection"
                  ),
    
                  # TODO: add Foundry IQ MCP tool
                  MCPTool(
                      server_label="machine-wiki",
                      server_url=machine_wiki_mcp_endpoint,
                      require_approval="never",
                      project_connection_id="machine-wiki-connection"
                  )
    
              ]
              
    
          ))
      print(f"✅ Created Fault Diagnosis Agent: {agent.id}")
      # Test the agent with a simple query
      print("\n🧪 Testing the agent with a sample query...")
      try:
    
          # Get the OpenAI client for responses and conversations
          openai_client = project_client.get_openai_client()
    
          # Create conversation
          conversation = openai_client.conversations.create()
    
          # Send request to trigger the MCP tools
          response = openai_client.responses.create(
              conversation=conversation.id,
              input="""
                  Hello, what can the issue be when machine-001 has curing temperature reading of 179.2°C that exceeds warning threshold of 178°C?
              """,
              extra_body={"agent": {"name": agent.name,
                                    "type": "agent_reference"}},
          )
    
          print(f"✅ Agent response: {response.output_text}")
      except Exception as test_error:
          print(
              f"⚠️  Agent test failed (but agent was still created): {test_error}")
    
      return agent
    

    except Exception as e:
    print(f"❌ Error creating agent: {e}")
    print("Make sure you have run 'az login' and have proper Azure credentials configured.")
    return None

if name == "main":
asyncio.run(main())

AI: Let me check what errors are occurring when running this file, and understand the current state:
AI: Good — MACHINE_MCP_SERVER_ENDPOINT is now set. Let me check the search endpoint format and run the agent to see the actual error:
AI: The agent is created but the machine-wiki-connection doesn't exist yet in the Foundry project. I also need to check the search endpoint trailing slash issue and then create the wiki connection. Let me check what connections exist and create the missing one:
AI: machine-wiki-connection is missing. I need to create it — it connects to the Foundry IQ knowledge base MCP endpoint on AI Search. Let me also check the knowledge base status and create the connection:
AI: The knowledge base hasn't been created yet (Task 3.2). Let me check the notebook to understand what it does, then run it programmatically:
AI: Now I have everything I need. I'll run all notebook cells in sequence — create knowledge source, knowledge base, test it, then create the machine-wiki-connection:
AI: The notebook isn't executing properly in thi...

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Jasazure <233270744+Jasazure@users.noreply.github.com>
Copilot AI changed the title [WIP] Summarize key points from Agentic AI Competition workshop Add competition entry doc + fix Cosmos DB parameterized queries Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants