![]() |
| https://www.pexels.com/photo/person-holding-compass-691637/ |
We may run into use cases when we need to figure out the intention of an incoming message to our agentic solution and the determine the appropriate way to handle it.
In this blog, we have a sample project demonstrating how to build a workflow using MicrosoftAgent Framework (MAF) to handle different types of user messages, including greetings, questions, inappropriate content, and general statements.
Source code can be found at https://github.com/dennisseah/maf-workflow
It uses Microsoft Agent Framework's Workflow API to create a workflow that processes user messages through various agents and handlers based on the intent detected in the message.
We created a simple use case to show how this works. The use case is user sends in a message, and based on the content of the message, the workflow routes the message to different handlers. The message can be one of the following types:
- Greeting: A friendly greeting message (e.g., "Hello", "Hi there!").
- Question: A message that contains a question or request for information (e.g., "What is 1 + 1?").
- Inappropriate Content: A message that contains inappropriate or offensive content (e.g., "You are stupid!").
- General Statement: A message that is a general statement or comment (e.g., "I love programming.").
In this above use case, we want to make sure that we handle each type of message appropriately. And only use LLM when necessary (i.e., for questions).
- When it is a greeting, the first LLM agent already generates a response, so we just return that.
- When it is inappropriate content, we return a standard message indicating that the content is not acceptable.
- For general statements, we return a standard acknowledgment message.
- For questions, we route the message to an assistant agent (LLM) to generate a response.
The LLM is used at most twice as explained above.
Implementation Details
| Workflow diagram |
- the square brackets indicate handlers
- the double square brackets indicate agents.
- The arrows show the flow of messages based on the detected intent.
- is_greeting (bool): true if the message is a greeting, false otherwise.
- is_question (bool): true if the message is a question or request for information, false otherwise.
- is_inappropriate (bool): true if the message is inappropriate, false otherwise.
- is_statement (bool): true if the message is a general statement, false otherwise.
- response (string): Generate a response to the message only if it is a greeting. For all other message types, return an empty string.
from pydantic import BaseModel
class IntentDetectionResult(BaseModel):
message_content: str = Field(..., description="The original message content.")
is_greeting: bool
is_inappropriate: bool
is_question: bool
is_statement: bool
response: str = Field(
...,
description="Generated response to the message if it is a greeting; empty string otherwise.",
)The Microsoft Agent Framework's Workflow feature provides us a way to create a directed acyclic graph for the above implementation.
Here is demo (without audio). Please view in full screen mode. Observe the 4 different types of messages and how they are handled accordingly.

Comments
Post a Comment