AI Agent in .NET Core
Hi All,
Microsoft has released their own Agentic AI framework now (as prerelease of course) You can now connect Azure AI, Open AI or any AI framework to this Microsoft Agentic AI to get response and work on those responses as you want.
I made a small AI agent as follows using Open AI to generate a speech and convert it to json format. Hope you like it
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;
using OpenAI;
using System;
using System.Reflection;
using System.Threading.Tasks;
string apiKey = "{OPENAI_API_KEY}";
IChatClient chatClient = new OpenAIClient(apiKey) .GetChatClient("gpt-4o-mini") .AsIChatClient();
Create two agents (writer and editor)
AIAgent writer = new ChatClientAgent(chatClient, newChatClientAgentOptions
{
Name = "writer",
Instructions = "Write engaging and motivational Toastmasters speeches."
});
AIAgent editor = new ChatClientAgent(chatClient, newChatClientAgentOptions
{
Name = "editor",
Instructions = "Edit and polish Toastmasters speeches for clarity, tone, flow and convert it to json format"
});
// Build a sequential workflow
Workflow workflow = AgentWorkflowBuilder.BuildSequential(writer, editor);
// Convert workflow into a single agent
AIAgent workflowAgent = await workflow.AsAgentAsync();
// Run the workflow
AgentRunResponse response = await workflowAgent.RunAsync(
"Write a Toastmasters speech about mentorship"
);
Console.WriteLine("\n--- FINAL OUTPUT ---\n");
Console.WriteLine(response.Text);
response of the agent
**Title: The Power of Mentorship: Lighting the Path to Success**
**Introduction:**
Fellow Toastmasters and esteemed guests, good evening! Today, I stand before you to share a powerful catalyst for personal and professional growth – mentorship. When you think of someone who has impacted your life, it often comes down to a mentor. A mentor is not just a teacher; they are a guide, a confidant, and sometimes, a friend who helps illuminate our path through the fog of uncertainty.
**Body:**
**1. The Definition: What is Mentorship?**
Mentorship is a relationship that brings together the experience of one and the aspirations of another. It's that invaluable connection where knowledge is shared, wisdom is passed down, and dreams are nurtured. As the saying goes, “A mentor is someone who sees more talent and ability within you than you see in yourself.”
**2. The Benefits of Having a Mentor:**
Think back to your journey. Have you ever faced a challenge that felt insurmountable? Maybe it was a career transition, a daunting presentation, or even a personal struggle. How much easier would these moments have been with someone experienced by your side, guiding you through?
A mentor offers perspective. They provide insight based on their experiences – experiences that can save you time, effort, and sometimes heartache. They challenge you to think bigger and aim higher. Studies show that mentees are more likely to advance in their careers, report increased job satisfaction, and take on leadership roles. The benefits are tremendous, both in personal growth and professional advancement.
**3. Becoming a Mentor: Giving Back:**
But mentorship is not a one-way street. As we benefit from mentors in our lives, we have an obligation to pay it forward. Becoming a mentor allows us to share our knowledge and experiences, impacting others as we once were. The warmth of guiding someone through their struggles, celebrating their triumphs, and just being there for them is a gift we should all experience.
I remember my first experience as a mentor. A young intern came into our workplace filled with hopes and uncertainties. I shared my stories, offered advice, and, most importantly, I listened. Watching her grow and succeed was one of the most rewarding experiences of my life. Gifting someone with your time and attention can yield incredible results.
**4. Finding the Right Mentor:**
Now, you might be wondering, “How do I find a mentor?” It starts with knowing what you seek. Reflect on your goals and identify individuals who embody the qualities you aspire to possess. It could be someone in your industry, a seasoned professional, or even a friend who's excelled in a particular area. Don't hesitate to reach out. Most people cherish the opportunity to share their journey with others.
**Conclusion:**
In closing, I want to remind you of the profound impact that mentorship can have on our lives. Whether you are seeking a mentor or aspiring to become one, embrace these opportunities. Together, we can create a culture of support and encouragement that uplifts us all.
As we continue on this journey of self-improvement, let's remember the words of author and mentor, Simon Sinek: “The greatest gift of leadership is a boss who wants you to be successful.” Let us be the leaders who cultivate the next generation, thus lighting the path to success for yet another. Thank you.
```json
{
"title": "The Power of Mentorship: Lighting the Path to Success",
"introduction": {
"greeting": "Fellow Toastmasters and esteemed guests, good evening!",
"purpose": "Today, I stand before you to share a powerful catalyst for personal and professional growth – mentorship.",
"definition": "When you think of someone who has impacted your life, it often comes down to a mentor. A mentor is not just a teacher; they are a guide, a confidant, and sometimes, a friend who helps illuminate our path through the fog of uncertainty."
},
"body": {
"1": {
"heading": "The Definition: What is Mentorship?",
"content": "Mentorship is a relationship that brings together the experience of one and the aspirations of another. It's that invaluable connection where knowledge is shared, wisdom is passed down, and dreams are nurtured. As the saying goes, “A mentor is someone who sees more talent and ability within you than you see in yourself.”"
},
"2": {
"heading": "The Benefits of Having a Mentor:",
"content": "Think back to your journey. Have you ever faced a challenge that felt insurmountable? Maybe it was a career transition, a daunting presentation, or even a personal struggle. How much easier would these moments have been with someone experienced by your side, guiding you through? A mentor offers perspective. They provide insight based on their experiences – experiences that can save you time, effort, and sometimes heartache. They challenge you to think bigger and aim higher. Studies show that mentees are more likely to advance in their careers, report increased job satisfaction, and take on leadership roles. The benefits are tremendous, both in personal growth and professional advancement."
},
"3": {
"heading": "Becoming a Mentor: Giving Back:",
"content": "But mentorship is not a one-way street. As we benefit from mentors in our lives, we have an obligation to pay it forward. Becoming a mentor allows us to share our knowledge and experiences, impacting others as we once were. The warmth of guiding someone through their struggles, celebrating their triumphs, and just being there for them is a gift we should all experience. I remember my first experience as a mentor. A young intern came into our workplace filled with hopes and uncertainties. I shared my stories, offered advice, and, most importantly, I listened. Watching her grow and succeed was one of the most rewarding experiences of my life. Gifting someone with your time and attention can yield incredible results."
},
"4": {
"heading": "Finding the Right Mentor:",
"content": "Now, you might be wondering, “How do I find a mentor?” It starts with knowing what you seek. Reflect on your goals and identify individuals who embody the qualities you aspire to possess. It could be someone in your industry, a seasoned professional, or even a friend who's excelled in a particular area. Don't hesitate to reach out. Most people cherish the opportunity to share their journey with others."
}
},
"conclusion": {
"content": "In closing, I want to remind you of the profound impact that mentorship can have on our lives. Whether you are seeking a mentor or aspiring to become one, embrace these opportunities. Together, we can create a culture of support and encouragement that uplifts us all. As we continue on this journey of self-improvement, let's remember the words of author and mentor, Simon Sinek: “The greatest gift of leadership is a boss who wants you to be successful.” Let us be the leaders who cultivate the next generation, thus lighting the path to success for yet another. Thank you."
}
}
```
Comments
Post a Comment