Skip to content

Commit 7c22b97

Browse files
authored
Andre prepare day 4 (#4)
* feat: Implement MCP JSON-RPC 2.0 handler and refactor API decorators Signed-off-by: Andre Bossard <anbossar@microsoft.com> * fix: Update API decorators for optional HTTP path and clean up imports docs: Enhance LEVEL_UP.md with Copilot chat testing instructions Signed-off-by: Andre Bossard <anbossar@microsoft.com> * feat: Migrate task management to SQLModel ORM and update related documentation Signed-off-by: Andre Bossard <anbossar@microsoft.com> * feat: Implement LangGraph agent with Azure OpenAI integration and extend API decorators for tool conversion Signed-off-by: Andre Bossard <anbossar@microsoft.com> * feat: Refactor AgentService to use OpenAI SDK and enhance tool integration Signed-off-by: Andre Bossard <anbossar@microsoft.com> * feat: Refactor AgentService to integrate LangGraph and replace OpenAI SDK usage Signed-off-by: Andre Bossard <anbossar@microsoft.com> * fix: Correct docstring formatting in tool_wrapper for consistency Signed-off-by: Andre Bossard <anbossar@microsoft.com> * feat: Update documentation structure for Day 4 lessons and announcements Signed-off-by: Andre Bossard <anbossar@microsoft.com> --------- Signed-off-by: Andre Bossard <anbossar@microsoft.com>
1 parent aa053c7 commit 7c22b97

14 files changed

Lines changed: 1797 additions & 225 deletions

.env.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Azure OpenAI Configuration
2+
# Get your credentials from: https://portal.azure.com
3+
4+
# Your Azure OpenAI endpoint (e.g., https://your-resource.openai.azure.com/)
5+
AZURE_OPENAI_ENDPOINT=https://can-i-haz-houze-resource.services.ai.azure.com/api/projects/can-i-haz-houze
6+
7+
# Your Azure OpenAI API key
8+
AZURE_OPENAI_API_KEY=your-api-key-here
9+
10+
# The deployment name you created in Azure (e.g., gpt-4, gpt-35-turbo)
11+
AZURE_OPENAI_DEPLOYMENT=gpt-5-mini
12+
13+
# API version - use latest stable version
14+
# See: https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning
15+
AZURE_OPENAI_API_VERSION=2024-05-01-preview
16+
17+
# Optional: Frontend build path override
18+
# FRONTEND_DIST=/path/to/custom/frontend/dist

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ Thumbs.db
4949
# Logs
5050
*.log
5151
logs/
52+
*.db

AGENTS_IMPLEMENTATION.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# LangGraph Agent Implementation - Summary
2+
3+
## ✅ Implementation Complete
4+
5+
Successfully created a complete LangGraph agent playground with Azure OpenAI integration for the Python Quart application.
6+
7+
## What Was Built
8+
9+
### 1. **Extended API Decorator System** ([backend/api_decorators.py](backend/api_decorators.py))
10+
- Added `Operation.to_langchain_tool()` method to convert operations into LangChain StructuredTool
11+
- Added `get_langchain_tools()` function to get all registered operations as tools
12+
- Optional LangChain imports with graceful degradation
13+
14+
### 2. **Agent Service** ([backend/agents.py](backend/agents.py))
15+
- **Pydantic Models**: `AgentRequest`, `AgentResponse` with validation
16+
- **AgentService**: Deep module with ReAct agent implementation
17+
- **Azure OpenAI Integration**: Uses `langchain-openai.AzureChatOpenAI`
18+
- **Automatic Tool Discovery**: Loads all `@operation` decorated functions as tools
19+
- **ReAct Loop**: Reasoning + Acting pattern with autonomous tool selection
20+
21+
### 3. **App Integration** ([backend/app.py](backend/app.py))
22+
- Added `load_dotenv()` for environment variable support
23+
- Imported and initialized `AgentService` with error handling
24+
- Created `@operation` decorated `op_run_agent()`
25+
- Added REST wrapper at `POST /api/agents/run`
26+
27+
### 4. **Configuration** ([.env.example](.env.example))
28+
- Azure OpenAI endpoint configuration
29+
- API key management
30+
- Deployment and API version settings
31+
32+
### 5. **Dependencies** ([backend/requirements.txt](backend/requirements.txt))
33+
- `python-dotenv==1.2.1` - Environment variables
34+
- `langchain==1.1.0` - LangChain framework (latest)
35+
- `langgraph==1.0.4` - LangGraph orchestration (latest)
36+
- `openai==2.8.1` - OpenAI SDK (latest)
37+
- `langchain-openai>=0.3.0` - Azure integration (latest)
38+
39+
### 6. **Documentation** ([docs/AGENTS.md](docs/AGENTS.md))
40+
- Complete setup guide
41+
- Architecture explanation
42+
- Usage examples
43+
- Troubleshooting
44+
- Advanced topics
45+
46+
## Key Features
47+
48+
**ReAct Agent Pattern**: Autonomous reasoning and tool execution
49+
**Automatic Tool Discovery**: All operations become agent tools
50+
**Type-Safe**: Pydantic models throughout
51+
**Unified Architecture**: REST + MCP + Agent tools from one decorator
52+
**Azure OpenAI**: Enterprise-ready with managed endpoints
53+
**Latest Versions**: All dependencies are latest stable releases
54+
55+
## Architecture Highlights
56+
57+
### Unified Operation → Tool Flow
58+
59+
```
60+
@operation decorator
61+
62+
├─→ REST endpoint (existing)
63+
├─→ MCP tool (existing)
64+
└─→ LangChain tool (NEW!)
65+
66+
Agent uses it automatically
67+
```
68+
69+
### Agent Execution Flow
70+
71+
```
72+
User Prompt
73+
74+
ReAct Agent (Azure OpenAI)
75+
76+
├─→ Reasoning: "I should create a task"
77+
├─→ Acting: Calls create_task tool
78+
├─→ Observing: Task created with ID xyz
79+
└─→ Response: "Created task successfully!"
80+
```
81+
82+
## What the Agent Can Do
83+
84+
The agent has access to all task operations:
85+
86+
- **Create** tasks from natural language
87+
- **Read** task details and lists
88+
- **Update** task properties
89+
- **Delete** tasks
90+
- **Query** task statistics
91+
- **Combine** multiple operations autonomously
92+
93+
Example prompts:
94+
- "Create 3 tasks: Learn LangGraph, Build agent, Test deployment"
95+
- "Show me all pending tasks"
96+
- "Mark the LangGraph task as completed"
97+
- "Delete all completed tasks"
98+
99+
## Quick Start
100+
101+
```bash
102+
# 1. Install dependencies
103+
pip install -r backend/requirements.txt
104+
105+
# 2. Configure Azure OpenAI
106+
cp .env.example .env
107+
# Edit .env with your credentials
108+
109+
# 3. Start server
110+
cd backend && python app.py
111+
112+
# 4. Test agent
113+
curl -X POST http://localhost:5001/api/agents/run \
114+
-H "Content-Type: application/json" \
115+
-d '{"prompt": "List all my tasks", "agent_type": "task_assistant"}'
116+
```
117+
118+
## Files Modified/Created
119+
120+
### Modified
121+
- ✏️ `backend/requirements.txt` - Added LangChain dependencies
122+
- ✏️ `backend/api_decorators.py` - Extended with LangChain tool support
123+
- ✏️ `backend/app.py` - Integrated agent service
124+
125+
### Created
126+
-`backend/agents.py` - Complete agent implementation
127+
-`.env.example` - Azure OpenAI configuration template
128+
-`docs/AGENTS.md` - Comprehensive documentation
129+
-`backend/test_agents.py` - Test utilities
130+
131+
## Design Principles Followed
132+
133+
**Grokking Simplicity**: Actions in services, calculations pure, data as models
134+
**Deep Modules**: `AgentService` has simple interface, complex implementation
135+
**Single Source of Truth**: Operations defined once, used everywhere
136+
**Pydantic Everywhere**: Type safety and automatic validation
137+
**Async by Default**: Matches Quart's async patterns
138+
139+
## Next Steps for Learning
140+
141+
1. **Test the ReAct agent** with various task management prompts
142+
2. **Experiment with custom workflows** using StateGraph (see `_build_state_graph()`)
143+
3. **Add memory** for conversation history across requests
144+
4. **Add RAG** for semantic task search
145+
5. **Build multi-agent system** with specialized roles
146+
147+
## References
148+
149+
- [LangGraph Docs](https://langchain-ai.github.io/langgraph/)
150+
- [LangChain Docs](https://docs.langchain.com/)
151+
- [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/)
152+
- [Full Documentation](docs/AGENTS.md)
153+
154+
---
155+
156+
**Status**: ✅ Ready for testing
157+
**Dependencies**: ✅ Installed
158+
**Configuration**: ⚠️ Requires Azure OpenAI credentials in .env
159+
**Documentation**: ✅ Complete

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ All deep-dive guides now live under `docs/` for easier discovery:
2727
- [Troubleshooting](docs/TROUBLESHOOTING.md) – common issues and fixes for setup, dev, and tests
2828

2929

30+
31+
32+
33+
3034
## 5-minute quick start (TL;DR)
3135
1. Clone the repo: `git clone <your-fork-url> && cd python-quart-vite-react`
3236
2. Run the automated bootstrap: `./setup.sh` (creates the repo-level `.venv`, installs frontend deps, installs Playwright, checks for Ollama)

0 commit comments

Comments
 (0)