massgen 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of massgen might be problematic. Click here for more details.
- massgen/__init__.py +94 -0
- massgen/agent_config.py +507 -0
- massgen/backend/CLAUDE_API_RESEARCH.md +266 -0
- massgen/backend/Function calling openai responses.md +1161 -0
- massgen/backend/GEMINI_API_DOCUMENTATION.md +410 -0
- massgen/backend/OPENAI_RESPONSES_API_FORMAT.md +65 -0
- massgen/backend/__init__.py +25 -0
- massgen/backend/base.py +180 -0
- massgen/backend/chat_completions.py +228 -0
- massgen/backend/claude.py +661 -0
- massgen/backend/gemini.py +652 -0
- massgen/backend/grok.py +187 -0
- massgen/backend/response.py +397 -0
- massgen/chat_agent.py +440 -0
- massgen/cli.py +686 -0
- massgen/configs/README.md +293 -0
- massgen/configs/creative_team.yaml +53 -0
- massgen/configs/gemini_4o_claude.yaml +31 -0
- massgen/configs/news_analysis.yaml +51 -0
- massgen/configs/research_team.yaml +51 -0
- massgen/configs/single_agent.yaml +18 -0
- massgen/configs/single_flash2.5.yaml +44 -0
- massgen/configs/technical_analysis.yaml +51 -0
- massgen/configs/three_agents_default.yaml +31 -0
- massgen/configs/travel_planning.yaml +51 -0
- massgen/configs/two_agents.yaml +39 -0
- massgen/frontend/__init__.py +20 -0
- massgen/frontend/coordination_ui.py +945 -0
- massgen/frontend/displays/__init__.py +24 -0
- massgen/frontend/displays/base_display.py +83 -0
- massgen/frontend/displays/rich_terminal_display.py +3497 -0
- massgen/frontend/displays/simple_display.py +93 -0
- massgen/frontend/displays/terminal_display.py +381 -0
- massgen/frontend/logging/__init__.py +9 -0
- massgen/frontend/logging/realtime_logger.py +197 -0
- massgen/message_templates.py +431 -0
- massgen/orchestrator.py +1222 -0
- massgen/tests/__init__.py +10 -0
- massgen/tests/multi_turn_conversation_design.md +214 -0
- massgen/tests/multiturn_llm_input_analysis.md +189 -0
- massgen/tests/test_case_studies.md +113 -0
- massgen/tests/test_claude_backend.py +310 -0
- massgen/tests/test_grok_backend.py +160 -0
- massgen/tests/test_message_context_building.py +293 -0
- massgen/tests/test_rich_terminal_display.py +378 -0
- massgen/tests/test_v3_3agents.py +117 -0
- massgen/tests/test_v3_simple.py +216 -0
- massgen/tests/test_v3_three_agents.py +272 -0
- massgen/tests/test_v3_two_agents.py +176 -0
- massgen/utils.py +79 -0
- massgen/v1/README.md +330 -0
- massgen/v1/__init__.py +91 -0
- massgen/v1/agent.py +605 -0
- massgen/v1/agents.py +330 -0
- massgen/v1/backends/gemini.py +584 -0
- massgen/v1/backends/grok.py +410 -0
- massgen/v1/backends/oai.py +571 -0
- massgen/v1/cli.py +351 -0
- massgen/v1/config.py +169 -0
- massgen/v1/examples/fast-4o-mini-config.yaml +44 -0
- massgen/v1/examples/fast_config.yaml +44 -0
- massgen/v1/examples/production.yaml +70 -0
- massgen/v1/examples/single_agent.yaml +39 -0
- massgen/v1/logging.py +974 -0
- massgen/v1/main.py +368 -0
- massgen/v1/orchestrator.py +1138 -0
- massgen/v1/streaming_display.py +1190 -0
- massgen/v1/tools.py +160 -0
- massgen/v1/types.py +245 -0
- massgen/v1/utils.py +199 -0
- massgen-0.0.3.dist-info/METADATA +568 -0
- massgen-0.0.3.dist-info/RECORD +76 -0
- massgen-0.0.3.dist-info/WHEEL +5 -0
- massgen-0.0.3.dist-info/entry_points.txt +2 -0
- massgen-0.0.3.dist-info/licenses/LICENSE +204 -0
- massgen-0.0.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Claude API Research for MassGen Backend
|
|
2
|
+
|
|
3
|
+
## API Status & Availability (2025)
|
|
4
|
+
|
|
5
|
+
✅ **Production Ready**: Claude API is stable and production-ready
|
|
6
|
+
✅ **Active Development**: Regular updates with new features in 2025
|
|
7
|
+
✅ **Strong SDK Support**: Official Python SDK with async/sync support
|
|
8
|
+
|
|
9
|
+
## Models Available (2025)
|
|
10
|
+
|
|
11
|
+
- **Claude 4 Opus**: Most capable, hybrid with extended thinking mode
|
|
12
|
+
- **Claude 4 Sonnet**: Balanced performance, also available to free users
|
|
13
|
+
- **Claude 3.7 Sonnet**: Previous generation, still supported
|
|
14
|
+
- **Claude 3.5 Haiku**: Fastest, cost-effective option
|
|
15
|
+
|
|
16
|
+
## Tool Use Capabilities
|
|
17
|
+
|
|
18
|
+
### ✅ Excellent Multi-Tool Support
|
|
19
|
+
**Key Advantage**: Claude can combine ALL tool types in a single request:
|
|
20
|
+
- ✅ **Server-side tools** (web search, code execution)
|
|
21
|
+
- ✅ **User-defined functions** (custom tools)
|
|
22
|
+
- ✅ **File processing** via Files API
|
|
23
|
+
- ✅ **No restrictions** on combining different tool types
|
|
24
|
+
|
|
25
|
+
### Tool Types Supported
|
|
26
|
+
|
|
27
|
+
#### 1. Server-Side Tools (Builtin)
|
|
28
|
+
**Web Search Tool:**
|
|
29
|
+
- Real-time web access with citations
|
|
30
|
+
- Progressive/chained searches supported
|
|
31
|
+
- Pricing: $10 per 1,000 searches
|
|
32
|
+
- Enable with tool definition in API request
|
|
33
|
+
|
|
34
|
+
**Code Execution Tool:**
|
|
35
|
+
- Python code execution in secure sandbox **server-side**
|
|
36
|
+
- 1 GiB RAM, 5 GiB storage, 1-hour sessions
|
|
37
|
+
- File upload support (CSV, Excel, JSON, images)
|
|
38
|
+
- Data analysis, visualization, calculations
|
|
39
|
+
- Pricing: $0.05 per session-hour (5 min minimum)
|
|
40
|
+
- **IMPORTANT**: Claude executes code server-side and streams results back
|
|
41
|
+
- **Execution results streamed** as additional content blocks
|
|
42
|
+
- **Tool type**: `code_execution_20250522` (requires beta headers)
|
|
43
|
+
- **Beta header required**: `"anthropic-beta": "code-execution-2025-05-22"`
|
|
44
|
+
- **Models supporting code execution**: Claude 3.5 Sonnet and above (NOT Haiku)
|
|
45
|
+
|
|
46
|
+
#### 2. Client-Side Tools (User-Defined)
|
|
47
|
+
- Custom function definitions with JSON schemas
|
|
48
|
+
- Parallel tool execution supported
|
|
49
|
+
- Chained/sequential tool calls
|
|
50
|
+
- No limitations on combining with server-side tools
|
|
51
|
+
|
|
52
|
+
## Streaming Support
|
|
53
|
+
|
|
54
|
+
### ✅ Advanced Streaming Capabilities
|
|
55
|
+
- **Basic streaming**: Real-time response generation
|
|
56
|
+
- **Tool use streaming**: Fine-grained streaming of tool parameters
|
|
57
|
+
- **Async support**: Full async/await patterns
|
|
58
|
+
- **SDK integration**: Built-in streaming helpers and accumulation
|
|
59
|
+
|
|
60
|
+
### Streaming with Tools
|
|
61
|
+
```python
|
|
62
|
+
# Fine-grained tool streaming (beta) - REQUIRES BETA CLIENT
|
|
63
|
+
stream = client.beta.messages.create(
|
|
64
|
+
model="claude-3-5-sonnet-20241022",
|
|
65
|
+
messages=[{"role": "user", "content": "Search and analyze..."}],
|
|
66
|
+
tools=[
|
|
67
|
+
{"type": "web_search_20250305"},
|
|
68
|
+
{"type": "code_execution_20250522"}
|
|
69
|
+
],
|
|
70
|
+
headers={"anthropic-beta": "code-execution-2025-05-22"},
|
|
71
|
+
stream=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
for event in stream:
|
|
75
|
+
if event.type == "content_block_delta":
|
|
76
|
+
# Stream tool input parameters incrementally
|
|
77
|
+
print(event.delta)
|
|
78
|
+
elif event.delta.type == "input_json_delta":
|
|
79
|
+
# Stream tool arguments as JSON fragments
|
|
80
|
+
print(event.delta.partial_json)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Authentication & Setup
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
# Simple setup
|
|
87
|
+
import anthropic
|
|
88
|
+
|
|
89
|
+
client = anthropic.Anthropic(
|
|
90
|
+
api_key="your-api-key" # or use ANTHROPIC_API_KEY env var
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# Async client
|
|
94
|
+
async_client = anthropic.AsyncAnthropic()
|
|
95
|
+
|
|
96
|
+
# IMPORTANT: For code execution, use the beta client
|
|
97
|
+
beta_client = anthropic.AsyncAnthropic()
|
|
98
|
+
response = await beta_client.beta.messages.create(
|
|
99
|
+
model="claude-3-5-sonnet-20241022",
|
|
100
|
+
tools=[{"type": "code_execution_20250522"}],
|
|
101
|
+
headers={"anthropic-beta": "code-execution-2025-05-22"},
|
|
102
|
+
messages=[...]
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Pricing Model
|
|
107
|
+
|
|
108
|
+
- **Token-based pricing**: Input/output tokens
|
|
109
|
+
- **Additional costs**:
|
|
110
|
+
- Web search: $10 per 1,000 searches
|
|
111
|
+
- Code execution: $0.05 per session-hour
|
|
112
|
+
- **No session limits**: Unlike Gemini Live API
|
|
113
|
+
- **Predictable scaling**: Standard REST API
|
|
114
|
+
|
|
115
|
+
## Advanced Features (2025)
|
|
116
|
+
|
|
117
|
+
### New Beta Features
|
|
118
|
+
- **Code execution**: Python sandbox with server-side execution
|
|
119
|
+
- Header: `"anthropic-beta": "code-execution-2025-05-22"`
|
|
120
|
+
- Tool type: `code_execution_20250522`
|
|
121
|
+
- **Interleaved thinking**: Claude can think between tool calls
|
|
122
|
+
- Header: `"anthropic-beta": "interleaved-thinking-2025-05-14"`
|
|
123
|
+
- **Fine-grained tool streaming**: Stream tool parameters without buffering
|
|
124
|
+
- **MCP Connector**: Connect to remote MCP servers from Messages API
|
|
125
|
+
|
|
126
|
+
### Extended Thinking Mode
|
|
127
|
+
- Available in Claude 4 models
|
|
128
|
+
- Can use tools during extended reasoning
|
|
129
|
+
- Alternates between thinking and tool use
|
|
130
|
+
|
|
131
|
+
## Architecture Compatibility with MassGen
|
|
132
|
+
|
|
133
|
+
### ✅ Perfect Fit for Requirements
|
|
134
|
+
|
|
135
|
+
**Multi-Tool Support:**
|
|
136
|
+
- ✅ Can combine web search + code execution + user functions
|
|
137
|
+
- ✅ No API limitations like Gemini
|
|
138
|
+
- ✅ Parallel and sequential tool execution
|
|
139
|
+
|
|
140
|
+
**Streaming Architecture:**
|
|
141
|
+
- ✅ Compatible with StreamChunk pattern
|
|
142
|
+
- ✅ Real-time tool parameter streaming
|
|
143
|
+
- ✅ Async generator support
|
|
144
|
+
|
|
145
|
+
**Production Readiness:**
|
|
146
|
+
- ✅ Stable API with predictable pricing
|
|
147
|
+
- ✅ No session limits or experimental restrictions
|
|
148
|
+
- ✅ Strong error handling and rate limits
|
|
149
|
+
|
|
150
|
+
## Implementation Recommendation
|
|
151
|
+
|
|
152
|
+
### ✅ HIGH PRIORITY: Implement Claude Backend
|
|
153
|
+
|
|
154
|
+
**Advantages for MassGen:**
|
|
155
|
+
1. **No tool restrictions** - can use all tool types together
|
|
156
|
+
2. **Production stable** - no experimental limitations
|
|
157
|
+
3. **Advanced streaming** - perfect for real-time coordination
|
|
158
|
+
4. **Strong Python SDK** - easy integration
|
|
159
|
+
5. **Competitive pricing** - especially for multi-agent use cases
|
|
160
|
+
|
|
161
|
+
**Implementation Priority:**
|
|
162
|
+
- **Higher than Gemini** - no API limitations
|
|
163
|
+
- **Complement to OpenAI/Grok** - provides third major backend option
|
|
164
|
+
- **Clean architecture** - no workarounds needed
|
|
165
|
+
|
|
166
|
+
### Suggested Implementation Order:
|
|
167
|
+
1. ✅ OpenAI Backend (completed)
|
|
168
|
+
2. ✅ Grok Backend (completed)
|
|
169
|
+
3. 🎯 **Claude Backend** (recommended next)
|
|
170
|
+
4. ⏳ Gemini Backend (when API supports multi-tools)
|
|
171
|
+
|
|
172
|
+
## Sample Integration
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
class ClaudeBackend(LLMBackend):
|
|
176
|
+
def __init__(self, api_key: Optional[str] = None):
|
|
177
|
+
self.client = anthropic.AsyncAnthropic(api_key=api_key)
|
|
178
|
+
|
|
179
|
+
async def stream_with_tools(self, messages, tools, **kwargs):
|
|
180
|
+
# Can freely combine all tool types
|
|
181
|
+
combined_tools = []
|
|
182
|
+
|
|
183
|
+
# Add server-side tools
|
|
184
|
+
if kwargs.get("enable_web_search"):
|
|
185
|
+
combined_tools.append({"type": "web_search_20250305"})
|
|
186
|
+
|
|
187
|
+
if kwargs.get("enable_code_execution"):
|
|
188
|
+
combined_tools.append({"type": "code_execution_20250522"})
|
|
189
|
+
|
|
190
|
+
# Add user-defined tools
|
|
191
|
+
if tools:
|
|
192
|
+
combined_tools.extend(tools)
|
|
193
|
+
|
|
194
|
+
# Single API call with all tools - USE BETA CLIENT FOR CODE EXECUTION
|
|
195
|
+
headers = {}
|
|
196
|
+
if kwargs.get("enable_code_execution"):
|
|
197
|
+
headers["anthropic-beta"] = "code-execution-2025-05-22"
|
|
198
|
+
|
|
199
|
+
stream = await self.client.beta.messages.create(
|
|
200
|
+
model="claude-3-5-sonnet-20241022",
|
|
201
|
+
messages=messages,
|
|
202
|
+
tools=combined_tools,
|
|
203
|
+
headers=headers,
|
|
204
|
+
stream=True
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
async for event in stream:
|
|
208
|
+
yield StreamChunk(...)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Key Implementation Requirements
|
|
212
|
+
|
|
213
|
+
### ✅ CRITICAL: Code Execution Setup
|
|
214
|
+
- **Use beta client**: `client.beta.messages.create()` NOT `client.messages.create()`
|
|
215
|
+
- **Beta header required**: `"anthropic-beta": "code-execution-2025-05-22"`
|
|
216
|
+
- **Correct tool type**: `code_execution_20250522` NOT `bash_20250124`
|
|
217
|
+
- **Model requirement**: Claude 3.5 Sonnet or above (Haiku does NOT support code execution)
|
|
218
|
+
|
|
219
|
+
### ✅ Tool Execution Pattern
|
|
220
|
+
Claude's code execution is **server-side** - Claude executes the code and streams results back:
|
|
221
|
+
1. Send request with `code_execution_20250522` tool
|
|
222
|
+
2. Claude generates code and executes it server-side
|
|
223
|
+
3. Claude streams back execution results automatically
|
|
224
|
+
4. No client-side tool execution needed for code execution tools
|
|
225
|
+
|
|
226
|
+
### ✅ Streaming Event Types to Handle
|
|
227
|
+
- `content_block_start`: Tool use begins
|
|
228
|
+
- `content_block_delta`: Tool input streaming
|
|
229
|
+
- `input_json_delta`: Tool arguments as JSON fragments
|
|
230
|
+
- Tool execution results are streamed as additional content blocks
|
|
231
|
+
|
|
232
|
+
### ✅ VERIFIED: Code Execution Streaming Flow
|
|
233
|
+
Based on successful test with `claude-3-5-haiku-latest`:
|
|
234
|
+
|
|
235
|
+
**Event Sequence:**
|
|
236
|
+
1. `message_start` - Stream begins
|
|
237
|
+
2. `content_block_start` -> `text` - Initial explanation text
|
|
238
|
+
3. `content_block_delta` -> `text_delta` - Text streaming (multiple events)
|
|
239
|
+
4. `content_block_stop` - Text block ends
|
|
240
|
+
5. `content_block_start` -> `server_tool_use` - Code execution tool begins
|
|
241
|
+
6. `content_block_delta` -> `input_json_delta` - **Python code streams in JSON fragments**
|
|
242
|
+
7. `content_block_stop` - Tool input complete
|
|
243
|
+
8. `content_block_start` -> `code_execution_tool_result` - **Server-side execution results**
|
|
244
|
+
9. `content_block_stop` - Tool result complete
|
|
245
|
+
10. `content_block_start` -> `text` - Analysis text
|
|
246
|
+
11. `content_block_delta` -> `text_delta` - Final analysis streaming
|
|
247
|
+
12. `content_block_stop` - Analysis complete
|
|
248
|
+
13. `message_stop` - Stream ends
|
|
249
|
+
|
|
250
|
+
**Key Implementation Details:**
|
|
251
|
+
- **Model**: `claude-3-5-haiku-latest` supports code execution
|
|
252
|
+
- **Beta setup**: `betas=["code-execution-2025-05-22"]` (not `extra_headers`)
|
|
253
|
+
- **Tool type**: `code_execution_20250522` with `name: "code_execution"`
|
|
254
|
+
- **Real-time code**: Events 27-47 show code streaming as JSON fragments
|
|
255
|
+
- **Server execution**: Claude executes code and streams results automatically
|
|
256
|
+
- **No client execution needed**: Unlike bash tools, code execution is server-side
|
|
257
|
+
|
|
258
|
+
## Conclusion
|
|
259
|
+
|
|
260
|
+
**Claude API is the ideal candidate for MassGen's next backend implementation** due to its:
|
|
261
|
+
- Complete multi-tool support without restrictions
|
|
262
|
+
- Production-ready stability and pricing
|
|
263
|
+
- Advanced streaming capabilities with server-side code execution
|
|
264
|
+
- Perfect alignment with architecture requirements
|
|
265
|
+
|
|
266
|
+
Unlike Gemini's API limitations, Claude provides the flexibility we need without compromising the architecture.
|