Task 4 — Work IQ: bring Microsoft 365 signals into an agent
Part of the Integrate agents with enterprise knowledge and Microsoft 365 lab. New here? Start with Getting started.
Set up (start here): This task needs a Foundry project (with a deployed model) and the starter code. If you haven’t already, complete Getting started to create your project, clone the code, and set
PROJECT_ENDPOINTandMODEL_DEPLOYMENT_NAMEinPython/.env. Then, from theLabfiles/B-integrate-agents-with-enterprise-knowledge-and-m365folder, verify you’re ready:
python setup/check_env.py --task 4
Note: This is an optional/advanced task that requires a Microsoft 365 Copilot license and Node.js 18 or later. It’s designed for enterprise learners or those with M365 Copilot access. Standard M365 accounts without Copilot won’t work. You can still read through the steps to understand the concepts.
Continuing from a previous task? If your project, virtual environment, and
.envare already set from an earlier task, you only need to install Work IQ (below), then go straight to Explore workplace intelligence scenarios.
Where Tasks 1-3 grounded an agent on documents, this task connects an agent to live Microsoft 365 signals — emails, meetings, Teams messages — using Work IQ. You’ll build a Tailwind Traders workplace intelligence agent that can prep for meetings, track projects, and extract action items from real M365 data.
What is Work IQ?
Work IQ is Microsoft’s contextual intelligence layer for Microsoft 365, exposed as a Model Context Protocol (MCP) server. It gives an agent permission-aware access to workplace data — emails, calendar, Teams messages, and documents — so the agent can reason over what people are actually doing and saying. It complements Foundry IQ (curated knowledge) with live workplace signals.
Install Work IQ
-
Open your terminal or command prompt.
-
Install Work IQ globally via npm:
npm install -g @microsoft/workiq -
Accept the End User License Agreement:
workiq accept-eula -
Test your Work IQ installation:
workiq ask -q "What meetings do I have today?" -
If the test succeeds - You’ll see meeting information from your M365 calendar. Continue to the next section.
-
If you see “Admin consent required”:
- The command will display a consent URL
- Send this URL to your IT administrator with the message: “I need Work IQ access for the Microsoft Learn AI Agents lab”
- Wait for admin approval, then retry the test command
-
If you see “No M365 Copilot license”:
- Unfortunately, you cannot complete this task without a Copilot license
- You can still read through the instructions to understand the concepts
Prepare the app
The Work IQ app is provided complete in the starter code — you run it as-is.
-
Open the
Pythonfolder and activate the virtual environment from Getting started:.\labenv\Scripts\Activate.ps1 -
Confirm your
.envhasPROJECT_ENDPOINTandMODEL_DEPLOYMENT_NAMEset (Work IQ uses the model deployment to run the agent). -
Review workiq_lab.py. It:
- Validates your Work IQ installation
- Connects to your Microsoft Foundry project
- Initializes the Work IQ MCP client (
npx -y @microsoft/workiq mcp) - Creates a
tailwind-workplace-agentwith the Work IQ tools - Displays an interactive menu with five scenarios
Explore workplace intelligence scenarios
-
Sign in to Azure, then run the app:
az loginpython workiq_lab.py
The application connects to Work IQ and your Foundry project, then shows a menu of five scenarios.
Meeting Prep scenario
-
From the main menu, select 1 - Meeting Prep.
- When prompted, enter a meeting topic or time, such as:
- “my 2pm meeting”
- “Spring Catalog Planning session”
- “store operations standup”
-
The agent will find your meeting details, search recent emails about the topic, look for previous meetings, summarize key points, and suggest discussion points.
- Review the output and note how sources are cited (emails, meetings, dates) and how the agent synthesizes information from multiple sources.
Project Status scenario
-
From the main menu, select 2 - Project Status.
- Enter a project name you’re working on, such as:
- “Spring Catalog Launch”
- “Store Refresh”
- “Supplier onboarding”
- The agent searches emails and Teams messages, finds related meetings, identifies recent decisions and blockers, and summarizes next steps and deadlines.
Action Items scenario
-
From the main menu, select 3 - Action Items.
-
Choose a time range (or press Enter for “this week”): “today”, “last 3 days”, “this month”.
-
The agent searches meeting notes, task-related emails, and Teams mentions, identifies items with deadlines, and prioritizes by urgency.
Combined Intelligence scenario
This scenario demonstrates using both Work IQ (workplace data) and Foundry IQ (knowledge base) together.
Note: This scenario requires Foundry IQ (Azure AI Search) configured in your project with an indexed knowledge base — for example, the Tailwind Traders knowledge base from Task 1.
-
From the main menu, select 4 - Combined Intelligence.
- Enter a topic that exists in both your workplace discussions and official documentation:
- “store return and rental policies”
- “supplier lead times”
- “guided-trip gear rentals”
- The agent searches workplace data (Work IQ) and the knowledge base (Foundry IQ), compares informal discussions with official documentation, identifies gaps, and provides a comprehensive summary with labeled sources.
Key insight:
- Work IQ tells you what people are actually doing and saying
- Foundry IQ tells you what’s officially documented
- Together they provide complete context for decision-making
Custom Query scenario
-
From the main menu, select 5 - Custom Query.
-
Try different types of workplace questions:
Find emails about the spring catalog from my managerWhat was decided in yesterday's store operations standup?Show me shared documents about supplier lead times -
Experiment with different time ranges, data sources, and follow-up questions to refine results.
View Work IQ capabilities
From the main menu, select 6 - View Work IQ Capabilities to review the architecture, data sources, security model, and the Work IQ vs. Foundry IQ comparison. Select 0 to exit — the app deletes the tailwind-workplace-agent version on the way out.
Understanding the code
Let’s examine the key patterns used in workiq_lab.py.
Pattern 1: Work IQ MCP client initialization
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Store server parameters for reuse
self.workiq_server_params = StdioServerParameters(
command="npx",
args=["-y", "@microsoft/workiq", "mcp"]
)
# Fetch available tools from Work IQ MCP server
async def _fetch():
async with stdio_client(self.workiq_server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools_result = await session.list_tools()
return tools_result.tools
raw_tools = asyncio.run(_fetch())
Rather than maintaining a persistent connection, a new MCP session is opened per operation. StdioServerParameters stores the command and arguments used to launch the Work IQ MCP server subprocess each time.
Pattern 2: Creating the agent with Work IQ tools
from azure.ai.projects.models import PromptAgentDefinition, FunctionTool
# Convert MCP tools to FunctionTool objects
workiq_tools = [
FunctionTool(
name=tool.name,
description=tool.description,
parameters=tool.inputSchema,
)
for tool in raw_tools
]
# Create agent with Work IQ tools
self.agent = self.project_client.agents.create_version(
agent_name="tailwind-workplace-agent",
definition=PromptAgentDefinition(
model=self.model_deployment,
instructions="You are a workplace intelligence assistant for Tailwind Traders staff...",
tools=workiq_tools # Work IQ tools added here
)
)
Each MCP tool is wrapped in a FunctionTool and passed to a PromptAgentDefinition.
Pattern 3: Tool call loop
After the initial response, the agent may request one or more Work IQ tool calls. These are executed and fed back to continue the conversation:
from openai.types.responses.response_input_param import FunctionCallOutput
while True:
if response.status == "failed":
break
input_list = []
for item in response.output:
if item.type == "function_call":
kwargs = json.loads(item.arguments)
result = self._call_workiq_tool(item.name, kwargs)
input_list.append(
FunctionCallOutput(
type="function_call_output",
call_id=item.call_id,
output=result.content[0].text,
)
)
if input_list:
response = self.openai_client.responses.create(
input=input_list,
previous_response_id=response.id,
extra_body={"agent_reference": {"name": self.agent.name, "type": "agent_reference"}}
)
else:
break # No more tool calls - final response ready
The loop continues until the agent produces a response with no pending function calls, at which point response.output_text contains the final answer.
✅ Checkpoint: You’ve built an agent that brings live Microsoft 365 signals into its reasoning through Work IQ, and seen how it complements the document-grounded agent from Task 1.
Clean up
The app deletes the tailwind-workplace-agent version when you exit. Work IQ uses your M365 license rather than creating Azure resources, so there’s nothing else to remove for this task. When you’re finished, enter deactivate to exit the virtual environment.
Troubleshooting
“Work IQ command not found” — Install Work IQ: npm install -g @microsoft/workiq
“Admin consent required” — Run workiq mcp to get the consent URL and send it to your IT admin, or use a personal M365 account with Copilot.
“No M365 Copilot license” — This task requires Copilot. Use an account with an M365 Copilot license, or read through the lab to understand the concepts.
“MCP server not responding” — Test Work IQ directly with workiq ask -q "What meetings do I have?". If it fails, reinstall with npm install -g @microsoft/workiq.
“No data returned” — Ensure your M365 account has emails, meetings, and Teams activity, and try broader queries.
Back to the lab overview.