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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# multillm
A unified async interface for multiple LLM providers with **agentic capabilities**. Switch between providers with a single line change.
## Features
- 🔄 **Unified API** - Same interface for OpenAI, Anthropic, Google, and more
- 🤖 **Agentic by default** - Automatic tool execution and multi-turn conversations
- 🛠️ **Interactive tools** - AI can ask you questions during execution
- 📦 **Provider flexibility** - Switch providers without changing code
- 🎯 **Simple CLI** - Quick testing and experimentation
- ⚡ **Async-first** - Built on asyncio for performance
## Quick Start
### CLI
```bash
# Install
pip install multillm-cli multillm-openai
# Simple query
multillm -m openai/gpt-4o -p "What is 2+2?"
# With interactive tools
multillm -m openai/gpt-4o -p "Ask me about my preferences" --use-tools ask_user
# With other tools
multillm -m openai/gpt-4o -p "What's the weather in Tokyo?" --use-tools get_weather
```
See [multillm-cli](packages/multillm-cli) for full CLI documentation.
### Python API
```bash
pip install multillm multillm-openai multillm-anthropic
```
**Simple query:**
```python
import asyncio
import multillm
async def main():
client = multillm.Client()
# Agentic API - works with any provider
async for msg in client.run("agentwrap/openai/gpt-4o", "Hello!"):
if msg.type == "text":
print(msg.content)
asyncio.run(main())
```
**With tools:**
```python
import asyncio
import multillm
# Define a tool
calculate = multillm.Tool(
name="calculate",
description="Perform a calculation",
parameters={
"type": "object",
"properties": {
"expression": {"type": "string"}
},
"required": ["expression"]
},
handler=lambda args: {"result": eval(args["expression"])}
)
async def main():
client = multillm.Client()
# AI can use tools automatically
async for msg in client.run(
"agentwrap/openai/gpt-4o",
"What's 25 * 4?",
tools=[calculate]
):
if msg.type == "text":
print(msg.content)
elif msg.type == "tool_use":
print(f"Using tool: {msg.tool_name}")
asyncio.run(main())
```
**Interactive tools:**
```python
import asyncio
import multillm
# Define interactive tool
ask_user = multillm.Tool(
name="ask_user",
description="Ask the user a question",
parameters={
"type": "object",
"properties": {
"question": {"type": "string"}
},
"required": ["question"]
},
handler=lambda args: {
"answer": input(f"\n{args['question']}\nYour answer: ")
}
)
async def main():
client = multillm.Client()
# AI can ask you questions!
async for msg in client.run(
"agentwrap/openai/gpt-4o",
"Help me plan a project by asking about my requirements",
tools=[ask_user]
):
if msg.type == "text":
print(msg.content)
asyncio.run(main())
```
## Packages
| Package | Description |
|---------|-------------|
| [multillm](packages/multillm) | Core library with unified client |
| [multillm-cli](packages/multillm-cli) | Command-line interface |
| **Chat Providers** | |
| [multillm-openai](packages/multillm-openai) | OpenAI GPT models |
| [multillm-anthropic](packages/multillm-anthropic) | Anthropic Claude chat API |
| [multillm-gemini](packages/multillm-gemini) | Google Gemini |
| [multillm-openrouter](packages/multillm-openrouter) | OpenRouter (access to 100+ models) |
| **Agent Providers** | |
| [multillm-agentwrap](packages/multillm-agentwrap) | Wrap chat providers with agentic capabilities |
| [multillm-claude](packages/multillm-claude) | Claude native agent with built-in tools |
## How It Works
### The Agentic API
All providers use the same **agentic API** powered by `run()`:
```python
async for msg in client.run(model, prompt, tools=tools):
# Process messages
```
**Message types:**
- `system` - Session started
- `text` - Text response from AI
- `tool_use` - AI is calling a tool
- `tool_result` - Tool execution result
- `result` - Final result
### Provider Format
**Chat providers with agentwrap:**
```python
"agentwrap/openai/gpt-4o"
"agentwrap/google/gemini-pro"
"agentwrap/anthropic/claude-3-5-sonnet-20241022"
```
**Native agent providers:**
```python
"claude/default"
"claude/claude-sonnet-4-20250514"
```
### What is agentwrap?
`agentwrap` wraps standard chat providers (OpenAI, Google, etc.) with agentic capabilities:
- ✅ Automatic tool execution
- ✅ Multi-turn conversations
- ✅ Tool calling loop
- ✅ Conversation history management
This means **any chat model** can work like an agent!
## Interactive Tools
AI models can ask you questions during execution:
**CLI:**
```bash
# Chat providers
multillm -m openai/gpt-4o -p "Ask me about my project" --use-tools ask_user
# Claude agent
multillm -m claude/default -p "Ask me about my project" \
--allowed-tools AskUserQuestion --permission-mode acceptEdits
```
**Python:**
```python
ask_user_tool = multillm.Tool(
name="ask_user",
description="Ask the user a question",
parameters={"type": "object", "properties": {"question": {"type": "string"}}},
handler=lambda args: {"answer": input(f"{args['question']}\nYour answer: ")}
)
async for msg in client.run("agentwrap/openai/gpt-4o", "Ask me questions", tools=[ask_user_tool]):
if msg.type == "text":
print(msg.content)
```
When the AI calls the tool, you'll see:
```
======================================================================
❓ QUESTION FROM ASSISTANT
======================================================================
What is your favorite programming language?
Your answer: _
```
See [CLI documentation](packages/multillm-cli) for more interactive tool examples.
## Configuration
### Environment Variables
```bash
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=...
```
### Programmatic
```python
client = multillm.Client(config={
"openai": {"api_key": "sk-..."},
"anthropic": {"api_key": "sk-ant-..."},
})
```
### Config Files
Create `~/.config/multillm/providers/<provider>.json`:
```json
{
"api_key": "sk-..."
}
```
See provider-specific documentation for all options:
- [OpenAI configuration](packages/multillm-openai)
- [Anthropic configuration](packages/multillm-anthropic)
- [Google Gemini configuration](packages/multillm-gemini)
- [Claude Agent configuration](packages/multillm-claude)
## Examples
### Chat with Different Providers
```python
import asyncio
import multillm
async def chat(model: str, prompt: str):
client = multillm.Client()
async for msg in client.run(model, prompt):
if msg.type == "text":
print(msg.content)
# All use the same API!
asyncio.run(chat("agentwrap/openai/gpt-4o", "Hello"))
asyncio.run(chat("agentwrap/google/gemini-pro", "Hello"))
asyncio.run(chat("agentwrap/anthropic/claude-3-5-sonnet-20241022", "Hello"))
asyncio.run(chat("claude/default", "Hello"))
```
### Custom Tools
```python
import asyncio
import multillm
from datetime import datetime
# Define custom tools
get_time = multillm.Tool(
name="get_current_time",
description="Get the current time",
parameters={"type": "object", "properties": {}},
handler=lambda args: {"time": datetime.now().isoformat()}
)
weather = multillm.Tool(
name="get_weather",
description="Get weather for a location",
parameters={
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"]
},
handler=lambda args: {"temp": 72, "condition": "sunny"}
)
async def main():
client = multillm.Client()
async for msg in client.run(
"agentwrap/openai/gpt-4o",
"What time is it and what's the weather in Tokyo?",
tools=[get_time, weather]
):
if msg.type == "text":
print(msg.content)
asyncio.run(main())
```
### Agent Options
```python
import asyncio
import multillm
async def main():
client = multillm.Client()
options = multillm.AgentOptions(
max_turns=10, # Max tool execution iterations
extra={
"temperature": 0.7,
"max_tokens": 2000
}
)
async for msg in client.run(
"agentwrap/openai/gpt-4o",
"Complex task requiring multiple steps",
options=options
):
if msg.type == "text":
print(msg.content)
asyncio.run(main())
```
## Claude Native Agent
Claude has a native agent provider with built-in tools:
```python
import asyncio
import multillm
async def main():
client = multillm.Client()
async for msg in client.run(
"claude/default",
"List Python files in current directory",
options=multillm.AgentOptions(
allowed_tools=["Bash", "Glob"],
permission_mode="acceptEdits",
max_turns=5
)
):
if msg.type == "text":
print(msg.content)
asyncio.run(main())
```
**Built-in tools:** Bash, Read, Write, Edit, Glob, Grep, Task, WebFetch, WebSearch, and more.
See [Claude Agent documentation](packages/multillm-claude) for details.
## Development
This is a uv workspace:
```bash
# Install
uv sync
# Run examples
uv run python examples/test-agentwrap.py
uv run python examples/test-interactive-tools.py
# Run CLI
uv run multillm -m openai/gpt-4o -p "Hello"
```
## Documentation
- [Getting Started Guide](INTERFACE_CONCEPTS.md) - Understand the API design
- [CLI Documentation](packages/multillm-cli/README.md) - Command-line usage
- [Agentwrap Provider](packages/multillm-agentwrap/README.md) - Wrapping chat models
- [Claude Agent Provider](packages/multillm-claude/README.md) - Native agent capabilities
- [Interactive Tools Guide](INTERACTIVE_TOOLS_IMPLEMENTATION.md) - Building interactive agents
- [Migration Guide](MIGRATION_SINGLE_TO_AGENTWRAP.md) - Updating from older versions
## Migration from single()
If you're using the deprecated `single()` API:
**Old:**
```python
result = await client.single("openai/gpt-4o", "Hello")
print(result.text)
```
**New:**
```python
async for msg in client.run("agentwrap/openai/gpt-4o", "Hello"):
if msg.type == "text":
print(msg.content)
```
See [Migration Guide](MIGRATION_SINGLE_TO_AGENTWRAP.md) for details.
## License
MIT
|