mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
First samples 1st batch
This commit is contained in:
@@ -9,13 +9,6 @@ concepts of **Agent Framework** one step at a time.
|
||||
pip install agent-framework --pre
|
||||
```
|
||||
|
||||
Set the required environment variables:
|
||||
|
||||
```bash
|
||||
export AZURE_AI_PROJECT_ENDPOINT="https://your-project-endpoint"
|
||||
export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o" # optional, defaults to gpt-4o
|
||||
```
|
||||
|
||||
## Samples
|
||||
|
||||
| # | File | What you'll learn |
|
||||
|
||||
@@ -70,7 +70,7 @@ async def log_model_input(context: ChatContext, call_next: Any) -> None:
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4o-mini")
|
||||
client = OpenAIChatClient(model="gpt-4o-mini")
|
||||
|
||||
# History provider loads/stores conversation messages in session.state.
|
||||
# skip_excluded=True means get_messages() will omit messages that were
|
||||
|
||||
@@ -25,11 +25,11 @@ from agent_framework import Agent
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.redis import RedisContextProvider
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
from redisvl.extensions.cache.embeddings import EmbeddingsCache
|
||||
from redisvl.utils.vectorize import OpenAITextVectorizer
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
load_dotenv()
|
||||
|
||||
# Default Redis URL for local Redis Stack.
|
||||
# Override via the REDIS_URL environment variable for remote or authenticated instances.
|
||||
|
||||
@@ -45,8 +45,7 @@ This folder contains examples demonstrating different ways to create and use age
|
||||
Make sure to set the following environment variables before running the examples:
|
||||
|
||||
- `OPENAI_API_KEY`: Your OpenAI API key
|
||||
- `OPENAI_CHAT_MODEL_ID`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`)
|
||||
- `OPENAI_RESPONSES_MODEL_ID`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`)
|
||||
- `OPENAI_MODEL`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`)
|
||||
- For image processing examples, use a vision-capable model like `gpt-4o` or `gpt-4o-mini`
|
||||
|
||||
Optionally, you can set:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from typing import Literal
|
||||
|
||||
from agent_framework import Agent
|
||||
from agent_framework import Agent, Message
|
||||
from agent_framework.anthropic import AnthropicClient
|
||||
from agent_framework.foundry import FoundryChatClient
|
||||
from agent_framework.openai import OpenAIChatClient, OpenAIChatOptions
|
||||
@@ -40,11 +40,11 @@ async def demo_anthropic_chat_client() -> None:
|
||||
print("\n=== Anthropic ChatClient with TypedDict Options ===\n")
|
||||
|
||||
# Create Anthropic client
|
||||
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
|
||||
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
|
||||
|
||||
# Standard options work great:
|
||||
response = await client.get_response(
|
||||
"What is the capital of France?",
|
||||
[Message("user", text="What is the capital of France?")],
|
||||
options={
|
||||
"temperature": 0.5,
|
||||
"max_tokens": 1000,
|
||||
@@ -62,7 +62,7 @@ async def demo_anthropic_agent() -> None:
|
||||
"""Demonstrate Agent with Anthropic client and typed options."""
|
||||
print("\n=== Agent with Anthropic and Typed Options ===\n")
|
||||
|
||||
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
|
||||
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
|
||||
|
||||
# Create a typed agent for Anthropic - IDE knows Anthropic-specific options!
|
||||
agent = Agent(
|
||||
@@ -119,12 +119,12 @@ async def demo_openai_chat_client_reasoning_models() -> None:
|
||||
print("\n=== OpenAI ChatClient with TypedDict Options ===\n")
|
||||
|
||||
# Create OpenAI client
|
||||
client = OpenAIChatClient[OpenAIReasoningChatOptions](model_id="o3")
|
||||
client = OpenAIChatClient[OpenAIReasoningChatOptions](model="o3")
|
||||
|
||||
# With specific options, you get full IDE autocomplete!
|
||||
# Try typing `client.get_response("Hello", options={` and see the suggestions
|
||||
response = await client.get_response(
|
||||
"What is 2 + 2?",
|
||||
[Message("user", text="What is 2 + 2?")],
|
||||
options={
|
||||
"max_tokens": 100,
|
||||
"allow_multiple_tool_calls": True,
|
||||
|
||||
@@ -44,8 +44,8 @@ Samples call `load_dotenv()` to automatically load environment variables from a
|
||||
|
||||
**Option 2: Export environment variables directly**:
|
||||
```bash
|
||||
export AZURE_AI_PROJECT_ENDPOINT="your-foundry-project-endpoint"
|
||||
export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o"
|
||||
export FOUNDRY_PROJECT_ENDPOINT="your-foundry-project-endpoint"
|
||||
export FOUNDRY_MODEL="gpt-4o"
|
||||
```
|
||||
|
||||
**Option 3: Using `env_file_path` parameter** (for per-client configuration):
|
||||
@@ -63,8 +63,8 @@ This allows different clients to use different configuration files if needed.
|
||||
|
||||
For the getting-started samples, you'll need at minimum:
|
||||
```bash
|
||||
AZURE_AI_PROJECT_ENDPOINT="your-foundry-project-endpoint"
|
||||
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o"
|
||||
FOUNDRY_PROJECT_ENDPOINT="your-foundry-project-endpoint"
|
||||
FOUNDRY_MODEL="gpt-4o"
|
||||
```
|
||||
|
||||
**Note for production**: In production environments, set environment variables through your deployment platform (e.g., Azure App Settings, Kubernetes ConfigMaps/Secrets) rather than using `.env` files. The `load_dotenv()` call in samples will have no effect when a `.env` file is not present, allowing environment variables to be loaded from the system.
|
||||
|
||||
Reference in New Issue
Block a user