mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
style: format all files with prettier
This commit is contained in:
@@ -24,6 +24,7 @@ Build sophisticated AI agent system for: $ARGUMENTS
|
||||
## Essential Architecture
|
||||
|
||||
### LangGraph State Management
|
||||
|
||||
```python
|
||||
from langgraph.graph import StateGraph, MessagesState, START, END
|
||||
from langgraph.prebuilt import create_react_agent
|
||||
@@ -35,6 +36,7 @@ class AgentState(TypedDict):
|
||||
```
|
||||
|
||||
### Model & Embeddings
|
||||
|
||||
- **Primary LLM**: Claude Sonnet 4.5 (`claude-sonnet-4-5`)
|
||||
- **Embeddings**: Voyage AI (`voyage-3-large`) - officially recommended by Anthropic for Claude
|
||||
- **Specialized**: `voyage-code-3` (code), `voyage-finance-2` (finance), `voyage-law-2` (legal)
|
||||
@@ -84,6 +86,7 @@ base_retriever = vectorstore.as_retriever(
|
||||
```
|
||||
|
||||
### Advanced RAG Patterns
|
||||
|
||||
- **HyDE**: Generate hypothetical documents for better retrieval
|
||||
- **RAG Fusion**: Multiple query perspectives for comprehensive results
|
||||
- **Reranking**: Use Cohere Rerank for relevance optimization
|
||||
@@ -117,6 +120,7 @@ tool = StructuredTool.from_function(
|
||||
## Production Deployment
|
||||
|
||||
### FastAPI Server with Streaming
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import StreamingResponse
|
||||
@@ -132,12 +136,14 @@ async def invoke_agent(request: AgentRequest):
|
||||
```
|
||||
|
||||
### Monitoring & Observability
|
||||
|
||||
- **LangSmith**: Trace all agent executions
|
||||
- **Prometheus**: Track metrics (requests, latency, errors)
|
||||
- **Structured Logging**: Use `structlog` for consistent logs
|
||||
- **Health Checks**: Validate LLM, tools, memory, and external services
|
||||
|
||||
### Optimization Strategies
|
||||
|
||||
- **Caching**: Redis for response caching with TTL
|
||||
- **Connection Pooling**: Reuse vector DB connections
|
||||
- **Load Balancing**: Multiple agent workers with round-robin routing
|
||||
@@ -165,6 +171,7 @@ results = await evaluate(
|
||||
## Key Patterns
|
||||
|
||||
### State Graph Pattern
|
||||
|
||||
```python
|
||||
builder = StateGraph(MessagesState)
|
||||
builder.add_node("node1", node1_func)
|
||||
@@ -176,6 +183,7 @@ agent = builder.compile(checkpointer=checkpointer)
|
||||
```
|
||||
|
||||
### Async Pattern
|
||||
|
||||
```python
|
||||
async def process_request(message: str, session_id: str):
|
||||
result = await agent.ainvoke(
|
||||
@@ -186,6 +194,7 @@ async def process_request(message: str, session_id: str):
|
||||
```
|
||||
|
||||
### Error Handling Pattern
|
||||
|
||||
```python
|
||||
from tenacity import retry, stop_after_attempt, wait_exponential
|
||||
|
||||
|
||||
Reference in New Issue
Block a user