Skip to main content

36 posts tagged with "Microsoft 365 Agents SDK"

Microsoft 365 Agents SDK for Building Intelligent Agents

View All Tags

Fixed: EtagException: AgentState 'conversation' could not save key because another turn updated the state first

· 14 min read
Jagdish Kumawat
Founder @ Dewiride

I sent two orders one right after the other to a Microsoft 365 Agents SDK agent whose order handler takes a few seconds. Both got a confirmation, then the second one also got AgentState 'conversation' could not save key ... because another turn updated the state first, and that order was gone. The SDK runs overlapping turns of one conversation at the same time, and refuses the save that comes second. The fix is to save before confirming, and to tell the person when their change didn't make it.

Fixed: System.ArgumentException: Scope 'T' not found in the Microsoft 365 Agents SDK

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

My Microsoft 365 Agents SDK agent answered every message with Scope 'T' not found the moment it used turnState.Private. The private conversation scope isn't part of the turn state the SDK creates by default, and the error message names a type parameter instead of the missing scope. The fix is to add the scope yourself, with a TurnStateFactory.

How to Add Middleware to an Agent in the Microsoft 365 Agents SDK in C#

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

Middleware in the Microsoft 365 Agents SDK runs for every activity, before your agent sees it and after your agent has finished, and it can change what your agent sends. That makes it the place for anything that applies to every conversation, whichever route answers: here, a disclaimer under every message the agent sends.

How to Replace the CloudAdapter Error Handler in the Microsoft 365 Agents SDK in C#

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

When a Microsoft 365 Agents SDK agent throws an exception it doesn't catch, the CloudAdapter handles it, and its default handler sends the exception's message to the user. A message like that can show a file path on your server to anyone chatting with your agent. One small class replaces that handler for every error.

How to Run Code Before Every Turn in the Microsoft 365 Agents SDK in C#

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

Some checks belong in front of every route: is this person allowed, is the agent switched on, is this the right kind of conversation? Instead of repeating them in each handler, the Microsoft 365 Agents SDK lets you register a before-turn handler that runs before the routes on every turn, and stops the turn when it returns false.

Fixed: The Microsoft 365 Agents SDK Sends the Exception Message to the User After OnTurnError

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

My Microsoft 365 Agents SDK agent showed people the raw message of any exception it didn't catch, so I added an OnTurnError handler with a friendly message, the way Microsoft Learn shows it. After that, people got both: my message, and then the raw one. AgentApplication passes every exception on to the adapter's error handler after yours runs, and the fix is to replace that handler.