opencomputer-agents-sdk 0.1.0__tar.gz

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.
@@ -0,0 +1,63 @@
1
+ # Dependencies
2
+ node_modules/
3
+ .pnp
4
+ .pnp.js
5
+
6
+ # Build outputs
7
+ dist/
8
+ build/
9
+ *.tsbuildinfo
10
+
11
+ # Environment files
12
+ .env.*
13
+ !.env.example
14
+ .env.local
15
+ .env.*.local
16
+
17
+ # Database
18
+ *.db
19
+ *.sqlite
20
+ *.sqlite3
21
+
22
+ # Logs
23
+ logs/
24
+ *.log
25
+ npm-debug.log*
26
+
27
+ # IDE
28
+ .idea/
29
+ .vscode/
30
+ *.swp
31
+ *.swo
32
+
33
+ # OS
34
+ .DS_Store
35
+ Thumbs.db
36
+
37
+ # Test coverage
38
+ coverage/
39
+
40
+ # Temporary files
41
+ tmp/
42
+ temp/
43
+
44
+ # Python
45
+ __pycache__/
46
+ *.py[cod]
47
+ *$py.class
48
+ *.so
49
+ .Python
50
+ env/
51
+ venv/
52
+ ENV/
53
+ env.bak/
54
+ venv.bak/
55
+ .pytest_cache/
56
+ .coverage
57
+ htmlcov/
58
+ .tox/
59
+ .cache
60
+ nosetests.xml
61
+ coverage.xml
62
+ *.cover
63
+ .hypothesis/
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: opencomputer-agents-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for OC Agents - Run AI agents programmatically
5
+ Project-URL: Homepage, https://opencomputer.dev
6
+ Project-URL: Documentation, https://opencomputer.dev/docs/sdk
7
+ Project-URL: Repository, https://github.com/opencomputer/agents-sdk
8
+ Project-URL: Issues, https://github.com/opencomputer/agents-sdk/issues
9
+ Author-email: OpenComputer <hello@opencomputer.dev>
10
+ License-Expression: MIT
11
+ Keywords: agents,ai,automation,opencomputer,sdk
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: httpx>=0.25.0
25
+ Requires-Dist: websockets>=12.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: mypy>=1.0; extra == 'dev'
28
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
29
+ Requires-Dist: pytest>=7.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # OC Agents SDK
34
+
35
+ Official Python SDK for [OC Agents](https://opencomputer.dev) - Run AI agents programmatically.
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install opencomputer-agents-sdk
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ```python
46
+ import asyncio
47
+ from oc_agents import OCAgents, RunOptions
48
+
49
+ async def main():
50
+ client = OCAgents(api_key='flt_xxx')
51
+ await client.connect()
52
+
53
+ # Run a task and wait for the result
54
+ result = await client.agents.run('agent-id', RunOptions(
55
+ prompt='Analyze the sales data and provide a summary'
56
+ ))
57
+
58
+ print(result.output) # Structured output (if agent has output_schema)
59
+ print(result.result) # Raw text output
60
+
61
+ await client.disconnect()
62
+
63
+ asyncio.run(main())
64
+ ```
65
+
66
+ ## Features
67
+
68
+ - **Real-time streaming** - Get live output as the agent works
69
+ - **Task control** - Cancel long-running tasks at any time
70
+ - **Structured output** - Define schemas for typed responses
71
+ - **Auto-reconnect** - Handles connection drops gracefully
72
+ - **Async/await** - Native Python async support
73
+
74
+ ## Usage
75
+
76
+ ### Simple: Run and Wait
77
+
78
+ ```python
79
+ async with OCAgents(api_key='flt_xxx') as client:
80
+ result = await client.agents.run('agent-id', RunOptions(
81
+ prompt='Analyze this data',
82
+ timeout=300.0, # 5 minutes max
83
+ ))
84
+
85
+ if result.output:
86
+ # Structured output (if agent has output_schema)
87
+ print(result.output['summary'])
88
+ print(result.output['confidence'])
89
+ ```
90
+
91
+ ### Advanced: Stream Events
92
+
93
+ ```python
94
+ from oc_agents import OCAgents, SubmitOptions
95
+
96
+ async def main():
97
+ client = OCAgents(api_key='flt_xxx')
98
+ await client.connect()
99
+
100
+ task = await client.agents.submit('agent-id', SubmitOptions(
101
+ prompt='Long running analysis task'
102
+ ))
103
+
104
+ # Listen to real-time events
105
+ task.on('stdout', lambda data: print(data, end=''))
106
+ task.on('tool_start', lambda tool, _: print(f'Using tool: {tool}'))
107
+ task.on('tool_end', lambda tool, _, duration: print(f'{tool} completed in {duration}ms'))
108
+ task.on('status', lambda status: print(f'Status: {status}'))
109
+
110
+ # Cancel if needed
111
+ # await asyncio.sleep(60)
112
+ # await task.cancel()
113
+
114
+ # Wait for final result
115
+ try:
116
+ result = await task.result()
117
+ print('Completed:', result.output)
118
+ except TaskCancelledError:
119
+ print('Task was cancelled')
120
+
121
+ await client.disconnect()
122
+
123
+ asyncio.run(main())
124
+ ```
125
+
126
+ ### List Agents
127
+
128
+ ```python
129
+ agents = await client.agents.list()
130
+ for agent in agents:
131
+ print(f"{agent.name} ({agent.id})")
132
+ print(f" Type: {agent.type}")
133
+ print(f" Provider: {agent.provider}")
134
+ ```
135
+
136
+ ### Context Manager
137
+
138
+ ```python
139
+ async with OCAgents(api_key='flt_xxx') as client:
140
+ result = await client.agents.run('agent-id', RunOptions(prompt='Hello'))
141
+ print(result.output)
142
+ # Automatically disconnects when done
143
+ ```
144
+
145
+ ## Error Handling
146
+
147
+ ```python
148
+ from oc_agents import (
149
+ OCAgents,
150
+ OCError,
151
+ TaskCancelledError,
152
+ TaskFailedError,
153
+ TaskTimeoutError,
154
+ AuthenticationError,
155
+ )
156
+
157
+ try:
158
+ result = await client.agents.run('agent-id', RunOptions(prompt='...'))
159
+ except TaskCancelledError:
160
+ print('Task was cancelled')
161
+ except TaskFailedError as e:
162
+ print(f'Task failed: {e.task_error}')
163
+ except TaskTimeoutError as e:
164
+ print(f'Task timed out after {e.timeout}s')
165
+ except AuthenticationError:
166
+ print('Invalid API key')
167
+ except OCError as e:
168
+ print(f'OC Agents error: {e} (code: {e.code})')
169
+ ```
170
+
171
+ ## Configuration
172
+
173
+ ```python
174
+ client = OCAgents(
175
+ api_key='flt_xxx', # Required: Your API key
176
+ base_url='https://api.opencomputer.dev', # Optional: API base URL
177
+ timeout=600.0, # Optional: Default timeout (10 min)
178
+ )
179
+ ```
180
+
181
+ ## API Reference
182
+
183
+ ### `OCAgents`
184
+
185
+ Main client class.
186
+
187
+ - `__init__(api_key, base_url, timeout)` - Create a new client
188
+ - `connect()` - Connect to OC Agents (required before using)
189
+ - `disconnect()` - Disconnect from OC Agents
190
+ - `is_connected()` - Check connection status
191
+ - `agents` - Access agents resource
192
+
193
+ ### `AgentsResource`
194
+
195
+ Resource for interacting with agents.
196
+
197
+ - `list()` - List all agents
198
+ - `get(agent_id)` - Get a specific agent
199
+ - `run(agent_id, options)` - Run a task and wait
200
+ - `submit(agent_id, options)` - Submit a task (non-blocking)
201
+
202
+ ### `TaskHandle`
203
+
204
+ Handle for managing a submitted task.
205
+
206
+ - `id` - Task ID
207
+ - `agent_id` - Agent ID
208
+ - `on(event, handler)` - Listen to events ('stdout', 'stderr', 'tool_start', 'tool_end', 'status')
209
+ - `cancel()` - Cancel the task
210
+ - `result()` - Wait for the result
211
+ - `get_status()` - Get current status
212
+ - `is_finished()` - Check if task is done
213
+ - `stream()` - Iterate over events (sync generator)
214
+
215
+ ### Types
216
+
217
+ - `RunOptions` - Options for running a task
218
+ - `SubmitOptions` - Options for submitting a task
219
+ - `TaskResult` - Result of a completed task
220
+ - `Agent` - Agent information
221
+ - `TaskStatus` - Task status enum
222
+
223
+ ## Requirements
224
+
225
+ - Python 3.9+
226
+ - websockets
227
+ - httpx
228
+
229
+ ## License
230
+
231
+ MIT
@@ -0,0 +1,199 @@
1
+ # OC Agents SDK
2
+
3
+ Official Python SDK for [OC Agents](https://opencomputer.dev) - Run AI agents programmatically.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install opencomputer-agents-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ import asyncio
15
+ from oc_agents import OCAgents, RunOptions
16
+
17
+ async def main():
18
+ client = OCAgents(api_key='flt_xxx')
19
+ await client.connect()
20
+
21
+ # Run a task and wait for the result
22
+ result = await client.agents.run('agent-id', RunOptions(
23
+ prompt='Analyze the sales data and provide a summary'
24
+ ))
25
+
26
+ print(result.output) # Structured output (if agent has output_schema)
27
+ print(result.result) # Raw text output
28
+
29
+ await client.disconnect()
30
+
31
+ asyncio.run(main())
32
+ ```
33
+
34
+ ## Features
35
+
36
+ - **Real-time streaming** - Get live output as the agent works
37
+ - **Task control** - Cancel long-running tasks at any time
38
+ - **Structured output** - Define schemas for typed responses
39
+ - **Auto-reconnect** - Handles connection drops gracefully
40
+ - **Async/await** - Native Python async support
41
+
42
+ ## Usage
43
+
44
+ ### Simple: Run and Wait
45
+
46
+ ```python
47
+ async with OCAgents(api_key='flt_xxx') as client:
48
+ result = await client.agents.run('agent-id', RunOptions(
49
+ prompt='Analyze this data',
50
+ timeout=300.0, # 5 minutes max
51
+ ))
52
+
53
+ if result.output:
54
+ # Structured output (if agent has output_schema)
55
+ print(result.output['summary'])
56
+ print(result.output['confidence'])
57
+ ```
58
+
59
+ ### Advanced: Stream Events
60
+
61
+ ```python
62
+ from oc_agents import OCAgents, SubmitOptions
63
+
64
+ async def main():
65
+ client = OCAgents(api_key='flt_xxx')
66
+ await client.connect()
67
+
68
+ task = await client.agents.submit('agent-id', SubmitOptions(
69
+ prompt='Long running analysis task'
70
+ ))
71
+
72
+ # Listen to real-time events
73
+ task.on('stdout', lambda data: print(data, end=''))
74
+ task.on('tool_start', lambda tool, _: print(f'Using tool: {tool}'))
75
+ task.on('tool_end', lambda tool, _, duration: print(f'{tool} completed in {duration}ms'))
76
+ task.on('status', lambda status: print(f'Status: {status}'))
77
+
78
+ # Cancel if needed
79
+ # await asyncio.sleep(60)
80
+ # await task.cancel()
81
+
82
+ # Wait for final result
83
+ try:
84
+ result = await task.result()
85
+ print('Completed:', result.output)
86
+ except TaskCancelledError:
87
+ print('Task was cancelled')
88
+
89
+ await client.disconnect()
90
+
91
+ asyncio.run(main())
92
+ ```
93
+
94
+ ### List Agents
95
+
96
+ ```python
97
+ agents = await client.agents.list()
98
+ for agent in agents:
99
+ print(f"{agent.name} ({agent.id})")
100
+ print(f" Type: {agent.type}")
101
+ print(f" Provider: {agent.provider}")
102
+ ```
103
+
104
+ ### Context Manager
105
+
106
+ ```python
107
+ async with OCAgents(api_key='flt_xxx') as client:
108
+ result = await client.agents.run('agent-id', RunOptions(prompt='Hello'))
109
+ print(result.output)
110
+ # Automatically disconnects when done
111
+ ```
112
+
113
+ ## Error Handling
114
+
115
+ ```python
116
+ from oc_agents import (
117
+ OCAgents,
118
+ OCError,
119
+ TaskCancelledError,
120
+ TaskFailedError,
121
+ TaskTimeoutError,
122
+ AuthenticationError,
123
+ )
124
+
125
+ try:
126
+ result = await client.agents.run('agent-id', RunOptions(prompt='...'))
127
+ except TaskCancelledError:
128
+ print('Task was cancelled')
129
+ except TaskFailedError as e:
130
+ print(f'Task failed: {e.task_error}')
131
+ except TaskTimeoutError as e:
132
+ print(f'Task timed out after {e.timeout}s')
133
+ except AuthenticationError:
134
+ print('Invalid API key')
135
+ except OCError as e:
136
+ print(f'OC Agents error: {e} (code: {e.code})')
137
+ ```
138
+
139
+ ## Configuration
140
+
141
+ ```python
142
+ client = OCAgents(
143
+ api_key='flt_xxx', # Required: Your API key
144
+ base_url='https://api.opencomputer.dev', # Optional: API base URL
145
+ timeout=600.0, # Optional: Default timeout (10 min)
146
+ )
147
+ ```
148
+
149
+ ## API Reference
150
+
151
+ ### `OCAgents`
152
+
153
+ Main client class.
154
+
155
+ - `__init__(api_key, base_url, timeout)` - Create a new client
156
+ - `connect()` - Connect to OC Agents (required before using)
157
+ - `disconnect()` - Disconnect from OC Agents
158
+ - `is_connected()` - Check connection status
159
+ - `agents` - Access agents resource
160
+
161
+ ### `AgentsResource`
162
+
163
+ Resource for interacting with agents.
164
+
165
+ - `list()` - List all agents
166
+ - `get(agent_id)` - Get a specific agent
167
+ - `run(agent_id, options)` - Run a task and wait
168
+ - `submit(agent_id, options)` - Submit a task (non-blocking)
169
+
170
+ ### `TaskHandle`
171
+
172
+ Handle for managing a submitted task.
173
+
174
+ - `id` - Task ID
175
+ - `agent_id` - Agent ID
176
+ - `on(event, handler)` - Listen to events ('stdout', 'stderr', 'tool_start', 'tool_end', 'status')
177
+ - `cancel()` - Cancel the task
178
+ - `result()` - Wait for the result
179
+ - `get_status()` - Get current status
180
+ - `is_finished()` - Check if task is done
181
+ - `stream()` - Iterate over events (sync generator)
182
+
183
+ ### Types
184
+
185
+ - `RunOptions` - Options for running a task
186
+ - `SubmitOptions` - Options for submitting a task
187
+ - `TaskResult` - Result of a completed task
188
+ - `Agent` - Agent information
189
+ - `TaskStatus` - Task status enum
190
+
191
+ ## Requirements
192
+
193
+ - Python 3.9+
194
+ - websockets
195
+ - httpx
196
+
197
+ ## License
198
+
199
+ MIT
@@ -0,0 +1,94 @@
1
+ """
2
+ OC Agents SDK for Python
3
+
4
+ Example:
5
+ ```python
6
+ import asyncio
7
+ from oc_agents import OCAgents, RunOptions
8
+
9
+ async def main():
10
+ client = OCAgents(api_key='flt_xxx')
11
+ await client.connect()
12
+
13
+ # Simple: run and wait for result
14
+ result = await client.agents.run('agent-id', RunOptions(
15
+ prompt='Analyze this data'
16
+ ))
17
+ print(result.output)
18
+
19
+ # Advanced: stream events and control task
20
+ task = await client.agents.submit('agent-id', SubmitOptions(
21
+ prompt='Long running task'
22
+ ))
23
+ task.on('stdout', print)
24
+ task.on('tool_start', lambda tool, _: print(f'Using {tool}...'))
25
+
26
+ # Cancel if needed
27
+ # await task.cancel()
28
+
29
+ # Wait for final result
30
+ result = await task.result()
31
+
32
+ await client.disconnect()
33
+
34
+ asyncio.run(main())
35
+ ```
36
+ """
37
+
38
+ __version__ = '0.1.0'
39
+
40
+ # Main client
41
+ from .client import OCAgents
42
+
43
+ # Task handle
44
+ from .task import TaskHandle
45
+
46
+ # Types
47
+ from .types import (
48
+ OCAgentsConfig,
49
+ Agent,
50
+ AgentType,
51
+ AgentProvider,
52
+ TaskResult,
53
+ TaskStatus,
54
+ RunOptions,
55
+ SubmitOptions,
56
+ )
57
+
58
+ # Errors
59
+ from .errors import (
60
+ OCError,
61
+ TaskCancelledError,
62
+ TaskFailedError,
63
+ TaskTimeoutError,
64
+ ConnectionError,
65
+ AuthenticationError,
66
+ AgentNotFoundError,
67
+ )
68
+
69
+ __all__ = [
70
+ # Client
71
+ 'OCAgents',
72
+
73
+ # Task
74
+ 'TaskHandle',
75
+
76
+ # Types
77
+ 'OCAgentsConfig',
78
+ 'Agent',
79
+ 'AgentType',
80
+ 'AgentProvider',
81
+ 'TaskResult',
82
+ 'TaskStatus',
83
+ 'RunOptions',
84
+ 'SubmitOptions',
85
+
86
+ # Errors
87
+ 'OCError',
88
+ 'TaskCancelledError',
89
+ 'TaskFailedError',
90
+ 'TaskTimeoutError',
91
+ 'ConnectionError',
92
+ 'AuthenticationError',
93
+ 'AgentNotFoundError',
94
+ ]