chapter two

2 Building Your First Agent Step by Step

 

This chapter covers

  • Building a simple AI-powered console application with Agent Framework
  • Obtaining and securing API keys for OpenAI and Azure OpenAI
  • Creating a basic console application for querying a GPT model
  • Creating your first AI agent

Let’s dive into practical applications with Agent Framework and see how to build AI-powered apps that use large language models. We’ll start with a simple console app that interacts with OpenAI’s GPT models, then move on to an agent that can control a robot car. You’ll also learn how to obtain and secure API keys, set up your development environment, connect Agent Framework to GPT models, and expose native (C#) functions as tools.

2.1 A Robot Car Story

Imagine a robot car that can sense fire danger and escape independently. While this concept may sound like something out of science fiction, it represents a real pet project that sparked the journey behind this book. The idea of creating an autonomous vehicle capable of detecting and responding to potential fire hazards highlights the fascinating intersection of robotics, sensor technology, and machine learning. This project was built on a very low budget, with a focus on exploring how these technologies could run in the .NET ecosystem on an IoT (Internet of Things) device.

2.1.1 A Fire-Detecting Robot Car

2.1.2 Challenges in Programming Complex Movements

2.1.3 Revisiting the Problem with Generative AI

2.1.4 The Spark that Ignites My Robot Car

2.2 Acquiring the API Keys

2.2.1 How to Get an OpenAI API Key

2.2.2 How to Get an Azure OpenAI API Key

2.2.3 Securing API Keys

2.3 Your First AI Agent

2.3.1 Crafting a Good Prompt

2.3.2 Structuring Prompts for Reusability and Scalability

2.3.3 Building a Stateless Agent with Agent Framework

2.3.4 Troubleshooting the application

2.3.5 Building a stateful agent with memory

2.3.6 Streaming Agent Responses

2.3.7 Building a Tool Agent with Actions

2.4 Conclusion

2.5 Summary