File: README.md

package info (click to toggle)
python-azure 20251118%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 783,356 kB
  • sloc: python: 6,474,533; ansic: 804; javascript: 287; sh: 205; makefile: 198; xml: 109
file content (84 lines) | stat: -rw-r--r-- 2,321 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# LangGraph Agent Calculator Sample

This sample demonstrates how to create a calculator agent using LangGraph and using it with Container Agent Adapter. The agent can perform basic arithmetic operations (addition, multiplication, and division) by utilizing tools and making decisions about when to use them.

## Overview

The sample consists of several key components:

- **LangGraph Agent**: A calculator agent that uses tools to perform arithmetic operations
- **Azure AI Agents Adapter**: Adapters of the LangGraph agents. It hosts the agent as a service on your local machine.


## Files Description

- `langgraph_agent_calculator.py` - The main LangGraph agent implementation with calculator tools
- `main.py` - HTTP server entry point using the agents adapter
- `.env-template` A template of environment variables for Azure OpenAI configuration



## Setup

1. **Environment Configuration**
   Create a `.env` file in this directory with your Azure OpenAI configuration:
   ```
   AZURE_OPENAI_API_KEY=your_api_key_here
   AZURE_OPENAI_ENDPOINT=your_endpoint_here
   AZURE_OPENAI_API_VERSION=2024-02-15-preview
   ```
   And install python-dotenv
   ```bash
   cd  container_agents/container_agent_adapter/python
   pip install python-dotenv
   ```

2. **Install Dependencies**
   Required Python packages (install via pip):
   ```bash
   cd  container_agents/container_agent_adapter/python
   pip install -e .[langgraph]
   ```

## Usage

### Running as HTTP Server

1. Start the agent server:
   ```bash
   python main.py
   ```
   The server will start on `http://localhost:8088`

2. Test the agent:
   ```bash
   curl -X POST http://localhost:8088/responses \
     -H "Content-Type: application/json" \
     -d '{
       "agent": {
         "name": "local_agent",
         "type": "agent_reference"
       },
       "stream": false,
       "input": "What is 15 divided by 3?"
     }'
   ```
   
   or 

   ```bash
   curl -X POST http://localhost:8088/responses \
     -H "Content-Type: application/json" \
     -d '{
       "agent": {
         "name": "local_agent",
         "type": "agent_reference"
       },
       "stream": false,
       "input": [{
          "type": "message",
          "role": "user",
          "content": [{"type": "input_text", "text": "What is 3 add 5?"}]
        }]
     }'
   ```