toolplane-python-client 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.
- toolplane_python_client-0.1.0/.flake8 +14 -0
- toolplane_python_client-0.1.0/.mypy-baseline +1 -0
- toolplane_python_client-0.1.0/ARCHITECTURE.md +83 -0
- toolplane_python_client-0.1.0/Dockerfile +35 -0
- toolplane_python_client-0.1.0/MANUAL.md +391 -0
- toolplane_python_client-0.1.0/PKG-INFO +543 -0
- toolplane_python_client-0.1.0/README.md +488 -0
- toolplane_python_client-0.1.0/README_EXAMPLES.md +128 -0
- toolplane_python_client-0.1.0/example.py +208 -0
- toolplane_python_client-0.1.0/example_client.py +173 -0
- toolplane_python_client-0.1.0/example_user.py +193 -0
- toolplane_python_client-0.1.0/pyproject.toml +143 -0
- toolplane_python_client-0.1.0/pytest.ini +4 -0
- toolplane_python_client-0.1.0/requirements.txt +27 -0
- toolplane_python_client-0.1.0/setup.cfg +4 -0
- toolplane_python_client-0.1.0/tests/conformance/.env.test.example +24 -0
- toolplane_python_client-0.1.0/tests/conformance/__init__.py +1 -0
- toolplane_python_client-0.1.0/tests/conformance/adapters/__init__.py +1 -0
- toolplane_python_client-0.1.0/tests/conformance/adapters/grpc_adapter.py +555 -0
- toolplane_python_client-0.1.0/tests/conformance/adapters/http_adapter.py +611 -0
- toolplane_python_client-0.1.0/tests/conformance/adapters/mcp_adapter.py +321 -0
- toolplane_python_client-0.1.0/tests/conformance/assertions.py +309 -0
- toolplane_python_client-0.1.0/tests/conformance/conftest.py +478 -0
- toolplane_python_client-0.1.0/tests/conformance/runner.py +1344 -0
- toolplane_python_client-0.1.0/tests/conformance/test_conformance_runner.py +135 -0
- toolplane_python_client-0.1.0/tests/test_errors.py +119 -0
- toolplane_python_client-0.1.0/tests/test_grpc_tls.py +120 -0
- toolplane_python_client-0.1.0/tests/test_provider_cli.py +162 -0
- toolplane_python_client-0.1.0/tests/test_request_wrappers.py +109 -0
- toolplane_python_client-0.1.0/tests/test_swe_failure_fidelity.py +101 -0
- toolplane_python_client-0.1.0/tests/test_tool_reconnect.py +62 -0
- toolplane_python_client-0.1.0/tests/test_wait_derivation.py +34 -0
- toolplane_python_client-0.1.0/toolplane/__init__.py +106 -0
- toolplane_python_client-0.1.0/toolplane/common/__init__.py +93 -0
- toolplane_python_client-0.1.0/toolplane/common/base_config.py +129 -0
- toolplane_python_client-0.1.0/toolplane/common/base_connection_manager.py +171 -0
- toolplane_python_client-0.1.0/toolplane/common/base_session_manager.py +321 -0
- toolplane_python_client-0.1.0/toolplane/common/base_tool_manager.py +347 -0
- toolplane_python_client-0.1.0/toolplane/common/constants.py +47 -0
- toolplane_python_client-0.1.0/toolplane/common/utils.py +310 -0
- toolplane_python_client-0.1.0/toolplane/core/__init__.py +67 -0
- toolplane_python_client-0.1.0/toolplane/core/config.py +107 -0
- toolplane_python_client-0.1.0/toolplane/core/connection.py +285 -0
- toolplane_python_client-0.1.0/toolplane/core/errors.py +298 -0
- toolplane_python_client-0.1.0/toolplane/core/machine.py +480 -0
- toolplane_python_client-0.1.0/toolplane/core/request.py +775 -0
- toolplane_python_client-0.1.0/toolplane/core/session.py +332 -0
- toolplane_python_client-0.1.0/toolplane/core/session_context.py +514 -0
- toolplane_python_client-0.1.0/toolplane/core/task.py +130 -0
- toolplane_python_client-0.1.0/toolplane/core/tool.py +329 -0
- toolplane_python_client-0.1.0/toolplane/http_core/__init__.py +37 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_config.py +97 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_connection.py +409 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_machine.py +298 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_request.py +748 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_session.py +348 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_session_context.py +491 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_task.py +101 -0
- toolplane_python_client-0.1.0/toolplane/http_core/http_tool.py +400 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/__init__.py +27 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/client_interface.py +122 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/connection_interface.py +193 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/event_interface.py +290 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/request_interface.py +439 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/session_interface.py +288 -0
- toolplane_python_client-0.1.0/toolplane/interfaces/tool_interface.py +441 -0
- toolplane_python_client-0.1.0/toolplane/proto/__init__.py +0 -0
- toolplane_python_client-0.1.0/toolplane/proto/service_pb2.py +315 -0
- toolplane_python_client-0.1.0/toolplane/proto/service_pb2_grpc.py +2240 -0
- toolplane_python_client-0.1.0/toolplane/provider_cli.py +268 -0
- toolplane_python_client-0.1.0/toolplane/provider_registry.py +77 -0
- toolplane_python_client-0.1.0/toolplane/provider_runtime.py +302 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/README.md +18 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/__init__.py +0 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/README.md +247 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/__init__.py +0 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/create_directory.py +94 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/create_file.py +124 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/file_search.py +229 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/grep_search.py +372 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/launcher.py +146 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/list_dir.py +395 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/pytest.ini +18 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/read_file.py +346 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/replace_string_in_file.py +407 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/requirements.txt +37 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/run_tests.py +66 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/semantic_search.py +485 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/standalone_toolkit.py +979 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/test_failure_analysis.py +618 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/standalone_tools/test_standalone_toolkit.py +517 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/__init__.py +35 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/create_directory.py +15 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/create_file.py +15 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/descriptions.py +273 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/execute_bash.py +93 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/file_editor.py +775 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/file_search.py +16 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/finish.py +50 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/grep_search.py +19 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/list_dir.py +407 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/read_file.py +18 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/replace_string_in_file.py +17 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/requirements.txt +3 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/search.py +260 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/semantic_search.py +20 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/str_replace_editor.py +647 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/submit.py +29 -0
- toolplane_python_client-0.1.0/toolplane/toolkits/swe/swe_toolkit.py +1296 -0
- toolplane_python_client-0.1.0/toolplane/toolplane_client.py +686 -0
- toolplane_python_client-0.1.0/toolplane/toolplane_http_client.py +681 -0
- toolplane_python_client-0.1.0/toolplane/utils/__init__.py +3 -0
- toolplane_python_client-0.1.0/toolplane/utils/schema.py +146 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/PKG-INFO +543 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/SOURCES.txt +193 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/dependency_links.txt +1 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/entry_points.txt +2 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/requires.txt +37 -0
- toolplane_python_client-0.1.0/toolplane_python_client.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[flake8]
|
|
2
|
+
max-line-length = 88
|
|
3
|
+
extend-ignore = E203,W503,D,ANN001,ANN002,ANN003,ANN101,ANN102,ANN201,ANN202,ANN204,ANN401,A001,A002,A003,A004,E501
|
|
4
|
+
exclude =
|
|
5
|
+
.git,
|
|
6
|
+
__pycache__,
|
|
7
|
+
build,
|
|
8
|
+
dist,
|
|
9
|
+
toolplane/proto,
|
|
10
|
+
toolplane/toolkits,
|
|
11
|
+
toolplane.egg-info,
|
|
12
|
+
toolplane_python_client.egg-info
|
|
13
|
+
per-file-ignores =
|
|
14
|
+
toolplane/__init__.py:F401
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1015
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Python Client Architecture
|
|
2
|
+
|
|
3
|
+
The Python client is the most complete SDK in the repository. It exposes both gRPC and HTTP facades, supports session management, remote invocation, streaming, and local tool-provider registration.
|
|
4
|
+
|
|
5
|
+
## Module Graph
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
toolplane/__init__.py
|
|
9
|
+
-> toolplane/toolplane_client.py
|
|
10
|
+
-> toolplane/provider_runtime.py
|
|
11
|
+
-> toolplane/core/*
|
|
12
|
+
-> toolplane/common/*
|
|
13
|
+
-> toolplane/interfaces/*
|
|
14
|
+
-> toolplane/toolplane_http_client.py
|
|
15
|
+
-> toolplane/http_core/*
|
|
16
|
+
-> toolplane/common/*
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Public Entry Points
|
|
20
|
+
|
|
21
|
+
- `toolplane/__init__.py`: public export surface for both transport facades and shared types.
|
|
22
|
+
- `toolplane/toolplane_client.py`: gRPC-first `Toolplane` facade.
|
|
23
|
+
- `toolplane/toolplane_http_client.py`: HTTP-first `ToolplaneHTTP` facade.
|
|
24
|
+
- `toolplane/provider_runtime.py`: explicit provider lifecycle surface shared by both transports.
|
|
25
|
+
|
|
26
|
+
## Top-Level API Surface
|
|
27
|
+
|
|
28
|
+
The two facades intentionally mirror each other closely.
|
|
29
|
+
|
|
30
|
+
### `Toolplane`
|
|
31
|
+
|
|
32
|
+
- Connection lifecycle: `connect()`, `disconnect()`, context-manager helpers.
|
|
33
|
+
- Session lifecycle (consumer scope — portable across maintained SDKs): `create_session()`, `get_session()`, `list_sessions()`.
|
|
34
|
+
- Session admin (admin scope — Python-only): `list_user_sessions()`, `bulk_delete_sessions()`, `get_session_stats()`, `invalidate_session()`.
|
|
35
|
+
- Tool invocation (consumer scope): `invoke()`, `ainvoke()`, `stream()`, `astream()`, `get_available_tools()`, `get_request_status()`.
|
|
36
|
+
- Provider runtime access: `provider_runtime()`.
|
|
37
|
+
- Backward-compatible provider aliases: `tool()`, `start()`, `stop()`.
|
|
38
|
+
|
|
39
|
+
### `ToolplaneHTTP`
|
|
40
|
+
|
|
41
|
+
- Mirrors most of the gRPC facade and adds explicit `health()` for HTTP health probing.
|
|
42
|
+
|
|
43
|
+
### `ProviderRuntime`
|
|
44
|
+
|
|
45
|
+
- Provider lifecycle: `create_session()`, `attach_session()`, `managed_session_ids()`.
|
|
46
|
+
- Tool registration: `register_tool()`, `tool()`.
|
|
47
|
+
- Runtime control: `poll_once()`, `start_in_background()`, `run_forever()`, `stop()`.
|
|
48
|
+
|
|
49
|
+
## Data Flow
|
|
50
|
+
|
|
51
|
+
### Remote invocation
|
|
52
|
+
|
|
53
|
+
1. User code creates an `Toolplane` or `ToolplaneHTTP` instance.
|
|
54
|
+
2. The client establishes a connection and initializes session context.
|
|
55
|
+
3. `invoke()` or `stream()` forwards the tool request through the relevant transport layer.
|
|
56
|
+
4. Session and request helpers normalize the response into Python-friendly objects.
|
|
57
|
+
|
|
58
|
+
### Provider mode
|
|
59
|
+
|
|
60
|
+
1. User creates or reuses an explicit `ProviderRuntime` from an `Toolplane` or `ToolplaneHTTP` client.
|
|
61
|
+
2. `ProviderRuntime.create_session()` or `ProviderRuntime.attach_session()` establishes machine ownership for the target session.
|
|
62
|
+
3. User decorates local callables with `ProviderRuntime.tool()`.
|
|
63
|
+
4. `ProviderRuntime.start_in_background()` or `ProviderRuntime.run_forever()` starts heartbeats and the provider poll loop.
|
|
64
|
+
5. Registered Python callables execute locally and results are sent back to the server.
|
|
65
|
+
|
|
66
|
+
## Key Folders
|
|
67
|
+
|
|
68
|
+
| Path | Responsibility |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `toolplane/core/` | gRPC-side connection, error, machine, request, session, and tool primitives |
|
|
71
|
+
| `toolplane/http_core/` | HTTP-side connection and session implementations |
|
|
72
|
+
| `toolplane/common/` | Shared configs, base managers, retries, validation, and cache helpers |
|
|
73
|
+
| `toolplane/interfaces/` | Interface and protocol contracts for client modules |
|
|
74
|
+
| `toolplane/toolkits/` | Toolkit-oriented helpers layered on top of the SDK |
|
|
75
|
+
| `toolplane/utils/` | General utility helpers |
|
|
76
|
+
| `toolplane/proto/` | Python protobuf outputs used by the gRPC facade |
|
|
77
|
+
|
|
78
|
+
## Notes For Agents
|
|
79
|
+
|
|
80
|
+
- When comparing SDK capability, use this client as the primary reference before checking Go or TypeScript.
|
|
81
|
+
- Public behavior is concentrated in `toolplane_client.py` and `toolplane_http_client.py`; lower-level folders mostly exist to support those facades.
|
|
82
|
+
- Provider execution is now explicit in `provider_runtime.py`; do not assume that `connect()` or consumer-side `create_session()` implies machine registration or background polling.
|
|
83
|
+
- If a feature appears in one Python transport facade, check the other facade before assuming parity is missing.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Use the official Ubuntu base image
|
|
2
|
+
FROM ubuntu:latest
|
|
3
|
+
|
|
4
|
+
# Set the working directory
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
# Install Python and pip
|
|
8
|
+
RUN apt-get update && apt-get install -y \
|
|
9
|
+
python3 \
|
|
10
|
+
python3-pip \
|
|
11
|
+
python3-venv \
|
|
12
|
+
&& apt-get clean
|
|
13
|
+
|
|
14
|
+
# Create a virtual environment
|
|
15
|
+
RUN python3 -m venv /app/venv
|
|
16
|
+
|
|
17
|
+
# Activate the virtual environment and install the wheel file
|
|
18
|
+
COPY dist/toolplane-0.1.0-py3-none-any.whl /app/toolplane-0.1.0-py3-none-any.whl
|
|
19
|
+
RUN /app/venv/bin/pip install --no-cache-dir /app/toolplane-0.1.0-py3-none-any.whl
|
|
20
|
+
|
|
21
|
+
# Copy the requirements.txt file into the container
|
|
22
|
+
COPY requirements.txt /app/requirements.txt
|
|
23
|
+
RUN /app/venv/bin/pip install --no-cache-dir -r /app/requirements.txt
|
|
24
|
+
|
|
25
|
+
# Copy the example.py script into container
|
|
26
|
+
COPY example.py /app/example.py
|
|
27
|
+
|
|
28
|
+
# Set up the folder to be mounted as root
|
|
29
|
+
VOLUME /root
|
|
30
|
+
|
|
31
|
+
# Ensure the container runs as root
|
|
32
|
+
USER root
|
|
33
|
+
|
|
34
|
+
# Run the example.py script using the virtual environment
|
|
35
|
+
CMD ["sh", "-c", "cd /root && /app/venv/bin/python /app/example.py \"$SESSION_ID\" \"$USER_ID\" \"$API_KEY\""]
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# Toolplane Python Client Documentation
|
|
2
|
+
|
|
3
|
+
> **This is the advanced API reference.** If you are new to Toolplane, start with the canonical first-touch path in `README.md` and the example walkthrough in `README_EXAMPLES.md`. Come back here for detailed constructor parameters, method signatures, and configuration options.
|
|
4
|
+
|
|
5
|
+
This manual documents the Python SDK as the primary maintained client for the Toolplane control plane. The maintained story is gRPC control-plane execution first, with `ToolplaneHTTP` available as a compatibility gateway surface over the same session, machine, request, and task flows.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This documentation covers the Modular Remote Procedure Call (Toolplane) Python client implementation. The client allows you to interact with Toolplane servers to register tools, manage sessions, and execute distributed functions.
|
|
10
|
+
|
|
11
|
+
## Architecture
|
|
12
|
+
|
|
13
|
+
The Toolplane Python client is organized into several key components:
|
|
14
|
+
|
|
15
|
+
- **Core Components**: Connection management, machine management, tool management, and request handling
|
|
16
|
+
- **Session Management**: Handles multiple session contexts
|
|
17
|
+
- **HTTP Client Alternative**: Provides HTTP-based communication as an alternative to gRPC
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install -r requirements.txt
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start Example
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from toolplane.toolplane_client import Toolplane
|
|
29
|
+
|
|
30
|
+
# Initialize client
|
|
31
|
+
client = Toolplane(
|
|
32
|
+
server_host="localhost",
|
|
33
|
+
server_port=9001,
|
|
34
|
+
user_id="user-456",
|
|
35
|
+
api_key="your-api-key",
|
|
36
|
+
)
|
|
37
|
+
client.connect()
|
|
38
|
+
|
|
39
|
+
# Provider side: create a machine-backed session and register tools through
|
|
40
|
+
# the explicit provider runtime (tools are session-scoped).
|
|
41
|
+
provider = client.provider_runtime()
|
|
42
|
+
session = provider.create_session(user_id="user-456", name="demo")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@provider.tool(session_id=session.session_id, name="echo_tool")
|
|
46
|
+
def echo_tool(input_str: str) -> str:
|
|
47
|
+
return f"Echo: {input_str}"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
provider.start_in_background()
|
|
51
|
+
|
|
52
|
+
# Consumer side: invoke in the same session and get the tool's result value.
|
|
53
|
+
result = client.invoke("echo_tool", session.session_id, input_str="Hello World")
|
|
54
|
+
print(result)
|
|
55
|
+
|
|
56
|
+
# Stop the background poll/heartbeat loop when done.
|
|
57
|
+
provider.stop()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Core Classes
|
|
61
|
+
|
|
62
|
+
### Toolplane (Main Client)
|
|
63
|
+
|
|
64
|
+
The main Toolplane client class that manages connections, sessions, and tools.
|
|
65
|
+
|
|
66
|
+
#### Constructor Parameters
|
|
67
|
+
|
|
68
|
+
| Parameter | Type | Description |
|
|
69
|
+
|-----------|------|-------------|
|
|
70
|
+
| `server_host` | str | Hostname of the Toolplane server |
|
|
71
|
+
| `server_port` | int | Port of the Toolplane server |
|
|
72
|
+
| `session_ids` | List[str] | List of session IDs to manage |
|
|
73
|
+
| `api_key` | Optional[str] | API key for authentication |
|
|
74
|
+
| `user_id` | Optional[str] | User identifier |
|
|
75
|
+
| `session_name` | Optional[str] | Name for the session |
|
|
76
|
+
| `session_description` | Optional[str] | Description of the session |
|
|
77
|
+
| `session_namespace` | Optional[str] | Namespace for the session |
|
|
78
|
+
| `heartbeat_interval` | int | Interval for heartbeat messages (seconds) |
|
|
79
|
+
| `max_workers` | int | Maximum number of worker threads |
|
|
80
|
+
| `request_timeout` | int | Request timeout in seconds |
|
|
81
|
+
| `poll_interval` | float | Interval for polling requests (seconds) |
|
|
82
|
+
| `max_retries` | int | Maximum number of retry attempts for connection failures |
|
|
83
|
+
| `retry_base_delay` | float | Initial delay between retries (seconds) |
|
|
84
|
+
| `retry_max_delay` | float | Maximum delay between retries (seconds) |
|
|
85
|
+
| `retry_backoff_factor` | float | Exponential backoff factor |
|
|
86
|
+
|
|
87
|
+
#### Methods
|
|
88
|
+
|
|
89
|
+
##### `connect() -> bool`
|
|
90
|
+
Establishes connection to the Toolplane server.
|
|
91
|
+
|
|
92
|
+
##### `disconnect() -> None`
|
|
93
|
+
Closes connection to the Toolplane server.
|
|
94
|
+
|
|
95
|
+
##### `create_session(session_id: Optional[str] = None, user_id: Optional[str] = None, name: Optional[str] = None, description: Optional[str] = None, namespace: Optional[str] = None, register_machine: bool = False) -> SessionContext`
|
|
96
|
+
Creates a new session on the server.
|
|
97
|
+
|
|
98
|
+
##### `get_session(session_id: str) -> Optional[SessionContext]`
|
|
99
|
+
Retrieves a session context by ID.
|
|
100
|
+
|
|
101
|
+
##### `list_sessions() -> List[SessionContext]`
|
|
102
|
+
Lists all active session contexts.
|
|
103
|
+
|
|
104
|
+
##### `tool(session_id: str, name: Optional[str] = None, description: Optional[str] = None, stream: bool = False, tags: Optional[List[str]] = None) -> Callable[[Callable], Callable]`
|
|
105
|
+
Decorator to register a tool for a session.
|
|
106
|
+
|
|
107
|
+
##### `invoke(tool_name: str, session_id: str, timeout_seconds: int = 0, wait_timeout: Optional[int] = None, **params) -> Any`
|
|
108
|
+
Invokes a tool in a session synchronously and returns the tool's result
|
|
109
|
+
value. `timeout_seconds` sets the request's absolute per-attempt timeout
|
|
110
|
+
on the wire; `wait_timeout` bounds the local wait (default:
|
|
111
|
+
timeout_seconds + 15, else 60). A lapsed wait raises
|
|
112
|
+
`ToolplaneTimeoutError` carrying the request ID.
|
|
113
|
+
|
|
114
|
+
##### `ainvoke(tool_name: str, session_id: str, **params) -> str`
|
|
115
|
+
Invokes a tool asynchronously.
|
|
116
|
+
|
|
117
|
+
##### `stream(tool_name: str, callback: Callable[[Any, bool], None], session_id: str, **params) -> List[Any]`
|
|
118
|
+
Streams tool execution results.
|
|
119
|
+
|
|
120
|
+
##### `astream(tool_name: str, callback: Callable[[Any, bool], None], session_id: str, **params) -> List[Any]`
|
|
121
|
+
Awaitable stream: runs the blocking stream loop in a worker thread and
|
|
122
|
+
resolves with the collected chunks.
|
|
123
|
+
|
|
124
|
+
##### `get_available_tools(session_id: str) -> Dict[str, Any]`
|
|
125
|
+
Gets available tools for a session.
|
|
126
|
+
|
|
127
|
+
##### `get_request_status(session_id: str, request_id: str) -> Dict[str, Any]`
|
|
128
|
+
Gets status of a request (arguments are session_id first, then request_id).
|
|
129
|
+
|
|
130
|
+
##### `start() -> None`
|
|
131
|
+
Starts the client and begins polling for requests.
|
|
132
|
+
|
|
133
|
+
##### `stop() -> None`
|
|
134
|
+
Stops the client and cleans up resources.
|
|
135
|
+
|
|
136
|
+
### ToolplaneHTTP (HTTP Client Alternative)
|
|
137
|
+
|
|
138
|
+
An HTTP-based alternative to the gRPC client.
|
|
139
|
+
|
|
140
|
+
#### Constructor Parameters
|
|
141
|
+
|
|
142
|
+
| Parameter | Type | Description |
|
|
143
|
+
|-----------|------|-------------|
|
|
144
|
+
| `server_host` | str | Hostname of the Toolplane server |
|
|
145
|
+
| `server_port` | int | Port of the Toolplane server |
|
|
146
|
+
| `session_ids` | List[str] | List of session IDs to manage |
|
|
147
|
+
| `api_key` | Optional[str] | API key for authentication |
|
|
148
|
+
| `user_id` | Optional[str] | User identifier |
|
|
149
|
+
| `session_name` | Optional[str] | Name for the session |
|
|
150
|
+
| `session_description` | Optional[str] | Description of the session |
|
|
151
|
+
| `session_namespace` | Optional[str] | Namespace for the session |
|
|
152
|
+
| `max_buffer_size` | int | Maximum buffer size for HTTP requests |
|
|
153
|
+
| `max_retries` | int | Maximum number of retry attempts |
|
|
154
|
+
| `request_timeout` | int | Request timeout in seconds |
|
|
155
|
+
| `retry_backoff_ms` | int | Initial backoff time for retries (milliseconds) |
|
|
156
|
+
| `heartbeat_interval` | int | Interval for heartbeat messages (seconds) |
|
|
157
|
+
| `max_workers` | int | Maximum number of worker threads |
|
|
158
|
+
| `poll_interval` | float | Interval for polling requests (seconds) |
|
|
159
|
+
|
|
160
|
+
#### Methods
|
|
161
|
+
|
|
162
|
+
Same as Toolplane client with the same signatures and functionality.
|
|
163
|
+
|
|
164
|
+
## Session Management
|
|
165
|
+
|
|
166
|
+
### SessionContext
|
|
167
|
+
|
|
168
|
+
Represents a session context with its own tools and machine registration.
|
|
169
|
+
|
|
170
|
+
#### Methods
|
|
171
|
+
|
|
172
|
+
##### `register_machine() -> bool`
|
|
173
|
+
Registers a machine for this session.
|
|
174
|
+
|
|
175
|
+
##### `register_tool(name: str, func: Callable, schema: Optional[Dict] = None, description: Optional[str] = None, stream: bool = False, tags: Optional[List[str]] = None) -> None`
|
|
176
|
+
Registers a tool for this session.
|
|
177
|
+
|
|
178
|
+
##### `invoke(tool_name: str, timeout_seconds: int = 0, wait_timeout: Optional[int] = None, **params) -> Any`
|
|
179
|
+
Invokes a tool in this session synchronously and returns the tool's result value.
|
|
180
|
+
|
|
181
|
+
##### `ainvoke(tool_name: str, **params) -> str`
|
|
182
|
+
Invokes a tool asynchronously.
|
|
183
|
+
|
|
184
|
+
##### `stream(tool_name: str, callback: Callable[[Any, bool], None], **params)`
|
|
185
|
+
Streams tool execution.
|
|
186
|
+
|
|
187
|
+
##### `get_available_tools() -> Dict[str, Any]`
|
|
188
|
+
Gets available tools for this session.
|
|
189
|
+
|
|
190
|
+
##### `get_request_status(request_id: str) -> Dict[str, Any]`
|
|
191
|
+
Gets status of a request.
|
|
192
|
+
|
|
193
|
+
## Tool Registration
|
|
194
|
+
|
|
195
|
+
Tools are registered using the `@client.tool` decorator:
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
@client.tool("session-123", name="my_tool", description="A sample tool")
|
|
199
|
+
def my_tool(param1: str, param2: int) -> str:
|
|
200
|
+
return f"Processed {param1} with {param2}"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Tool Registration Parameters
|
|
204
|
+
|
|
205
|
+
| Parameter | Type | Description |
|
|
206
|
+
|-----------|------|-------------|
|
|
207
|
+
| `session_id` | str | ID of the session to register the tool for |
|
|
208
|
+
| `name` | Optional[str] | Tool name (defaults to function name) |
|
|
209
|
+
| `description` | Optional[str] | Tool description |
|
|
210
|
+
| `stream` | bool | Whether tool supports streaming |
|
|
211
|
+
| `tags` | Optional[List[str]] | Tags for categorizing the tool |
|
|
212
|
+
|
|
213
|
+
## Error Handling
|
|
214
|
+
|
|
215
|
+
The client raises `ToolplaneError` for most operation failures and `ConnectionError` for connection-related issues.
|
|
216
|
+
|
|
217
|
+
## Type Safety
|
|
218
|
+
|
|
219
|
+
All public APIs are fully typed with proper type annotations to enable:
|
|
220
|
+
- Better IDE support (autocomplete, error detection)
|
|
221
|
+
- Static type checking with tools like `mypy`
|
|
222
|
+
- Self-documenting code
|
|
223
|
+
|
|
224
|
+
## Retry Logic
|
|
225
|
+
|
|
226
|
+
Both Toolplane clients now include comprehensive retry logic to handle transient failures:
|
|
227
|
+
|
|
228
|
+
### gRPC Client Retry Configuration
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
# Example with custom retry configuration
|
|
232
|
+
client = Toolplane(
|
|
233
|
+
server_host="localhost",
|
|
234
|
+
server_port=80,
|
|
235
|
+
max_retries=5,
|
|
236
|
+
retry_base_delay=2.0,
|
|
237
|
+
retry_max_delay=120.0,
|
|
238
|
+
retry_backoff_factor=3.0
|
|
239
|
+
)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### HTTP Client Retry Configuration
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
# Example with custom retry configuration
|
|
246
|
+
client = ToolplaneHTTP(
|
|
247
|
+
server_host="localhost",
|
|
248
|
+
server_port=8080,
|
|
249
|
+
max_retries=5,
|
|
250
|
+
retry_backoff_ms=500
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Retry Features
|
|
255
|
+
|
|
256
|
+
1. **Exponential Backoff**: Delays increase exponentially with each retry attempt
|
|
257
|
+
2. **Jitter**: Random variation to prevent thundering herds
|
|
258
|
+
3. **Configurable Limits**: Users can tune retry behavior to their needs
|
|
259
|
+
4. **Smart Error Detection**: Retries only on retryable errors (UNAVAILABLE, DEADLINE_EXCEEDED, etc.)
|
|
260
|
+
5. **Connection State Tracking**: Monitor connection health and recovery attempts
|
|
261
|
+
|
|
262
|
+
### Retry Parameters
|
|
263
|
+
|
|
264
|
+
| Parameter | Default Value | Description |
|
|
265
|
+
|-----------|---------------|-------------|
|
|
266
|
+
| `max_retries` | 3 | Maximum retry attempts |
|
|
267
|
+
| `retry_base_delay` | 1.0 seconds | Initial delay between retries |
|
|
268
|
+
| `retry_max_delay` | 60.0 seconds | Maximum delay between retries |
|
|
269
|
+
| `retry_backoff_factor` | 2.0 | Exponential backoff factor |
|
|
270
|
+
| `retry_backoff_ms` | 250 milliseconds | HTTP client initial backoff |
|
|
271
|
+
|
|
272
|
+
## Usage Examples
|
|
273
|
+
|
|
274
|
+
### Basic Usage
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from toolplane.toolplane_client import Toolplane
|
|
278
|
+
|
|
279
|
+
# Initialize client
|
|
280
|
+
client = Toolplane(
|
|
281
|
+
server_host="localhost",
|
|
282
|
+
server_port=80,
|
|
283
|
+
session_ids=["session-123"],
|
|
284
|
+
user_id="user-456",
|
|
285
|
+
api_key="your-api-key"
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
# Connect to server
|
|
289
|
+
client.connect()
|
|
290
|
+
|
|
291
|
+
# Register tools
|
|
292
|
+
@client.tool("session-123", name="echo")
|
|
293
|
+
def echo(input_str: str) -> str:
|
|
294
|
+
return f"Echo: {input_str}"
|
|
295
|
+
|
|
296
|
+
# Start client
|
|
297
|
+
client.start()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Asynchronous Tool Invocation
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
# Invoke tool asynchronously
|
|
304
|
+
request_id = client.ainvoke("echo", session_id="session-123", input_str="Hello World")
|
|
305
|
+
print(f"Request ID: {request_id}")
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Streaming Tool Execution
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
def callback(chunk, is_final):
|
|
312
|
+
print(f"Chunk: {chunk}")
|
|
313
|
+
|
|
314
|
+
# Stream tool execution
|
|
315
|
+
chunks = client.stream("echo", callback, session_id="session-123", input_str="Hello World")
|
|
316
|
+
print(f"Final result: {chunks}")
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Configuration
|
|
320
|
+
|
|
321
|
+
### Environment Variables
|
|
322
|
+
|
|
323
|
+
The client supports configuration through environment variables:
|
|
324
|
+
- `TOOLPLANE_SERVER_HOST` - Server hostname
|
|
325
|
+
- `TOOLPLANE_SERVER_PORT` - Server port
|
|
326
|
+
- `TOOLPLANE_API_KEY` - API key for authentication
|
|
327
|
+
- `TOOLPLANE_USER_ID` - User identifier
|
|
328
|
+
|
|
329
|
+
### Configuration Priority
|
|
330
|
+
|
|
331
|
+
1. Explicit constructor parameters
|
|
332
|
+
2. Environment variables
|
|
333
|
+
3. Default values
|
|
334
|
+
|
|
335
|
+
## Performance Considerations
|
|
336
|
+
|
|
337
|
+
- Uses thread pools for concurrent request handling
|
|
338
|
+
- Configurable worker count for heavy workloads
|
|
339
|
+
- Efficient connection reuse
|
|
340
|
+
- Heartbeat mechanism for connection liveness
|
|
341
|
+
|
|
342
|
+
## Troubleshooting
|
|
343
|
+
|
|
344
|
+
### Connection Issues
|
|
345
|
+
|
|
346
|
+
If you encounter connection problems:
|
|
347
|
+
1. Verify server address and port
|
|
348
|
+
2. Check network connectivity
|
|
349
|
+
3. Ensure the server is running
|
|
350
|
+
4. Confirm credentials are valid
|
|
351
|
+
|
|
352
|
+
### Timeout Issues
|
|
353
|
+
|
|
354
|
+
If operations timeout:
|
|
355
|
+
1. Increase `request_timeout` parameter
|
|
356
|
+
2. Check server performance
|
|
357
|
+
3. Monitor network latency
|
|
358
|
+
|
|
359
|
+
## Development Guidelines
|
|
360
|
+
|
|
361
|
+
### Code Style
|
|
362
|
+
|
|
363
|
+
- Follow PEP 8 guidelines
|
|
364
|
+
- Use descriptive variable names
|
|
365
|
+
- Include comprehensive docstrings
|
|
366
|
+
- Maintain type safety with proper annotations
|
|
367
|
+
|
|
368
|
+
### Testing
|
|
369
|
+
|
|
370
|
+
Write unit tests for all public APIs:
|
|
371
|
+
- Test connection establishment
|
|
372
|
+
- Test tool registration
|
|
373
|
+
- Test invocation scenarios
|
|
374
|
+
- Test error conditions
|
|
375
|
+
|
|
376
|
+
## Future Enhancements
|
|
377
|
+
|
|
378
|
+
### Planned Features
|
|
379
|
+
|
|
380
|
+
1. **Automatic Reconnection**: Built-in reconnection logic with exponential backoff
|
|
381
|
+
2. **Enhanced Logging**: More detailed logging for debugging
|
|
382
|
+
3. **Improved Retry Logic**: More sophisticated retry mechanisms
|
|
383
|
+
4. **Better Session Management**: Enhanced session lifecycle handling
|
|
384
|
+
5. **Async/Await Support**: Native async/await patterns for Python 3.7+
|
|
385
|
+
|
|
386
|
+
## Contributing
|
|
387
|
+
|
|
388
|
+
1. Fork the repository
|
|
389
|
+
2. Create feature branch
|
|
390
|
+
3. Write tests for new functionality
|
|
391
|
+
4. Submit pull request with clear description
|