keycase-agent-sdk 0.1.0b2__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.
- keycase_agent_sdk-0.1.0b2/LICENSE +21 -0
- keycase_agent_sdk-0.1.0b2/PKG-INFO +546 -0
- keycase_agent_sdk-0.1.0b2/README.md +499 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/__init__.py +99 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/agent.py +358 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/auth.py +271 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/config.py +135 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/decorators.py +414 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/event_handler.py +93 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/exceptions/__init__.py +24 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/exceptions/auth_exceptions.py +9 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/exceptions/validation_exceptions.py +78 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/execution_context.py +28 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/execution_manager.py +743 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/loader.py +65 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/models/__init__.py +32 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/models/execute_plan.py +232 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/models/execution_result.py +136 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/models/execution_run_mode_types.py +10 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/models/websocket_event_types.py +33 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/registry.py +15 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/state_tracker.py +47 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/utils/__init__.py +22 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/utils/auth_helper.py +259 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/utils/event_sender.py +119 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent/websocket_client.py +426 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/PKG-INFO +546 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/SOURCES.txt +38 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/dependency_links.txt +1 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/entry_points.txt +2 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/requires.txt +15 -0
- keycase_agent_sdk-0.1.0b2/keycase_agent_sdk.egg-info/top_level.txt +1 -0
- keycase_agent_sdk-0.1.0b2/pyproject.toml +143 -0
- keycase_agent_sdk-0.1.0b2/setup.cfg +21 -0
- keycase_agent_sdk-0.1.0b2/setup.py +20 -0
- keycase_agent_sdk-0.1.0b2/tests/test_agent_retry.py +259 -0
- keycase_agent_sdk-0.1.0b2/tests/test_config.py +187 -0
- keycase_agent_sdk-0.1.0b2/tests/test_execution_manager.py +356 -0
- keycase_agent_sdk-0.1.0b2/tests/test_websocket_client.py +403 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Keycase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: keycase-agent-sdk
|
|
3
|
+
Version: 0.1.0b2
|
|
4
|
+
Summary: Python SDK for Keycase Agent execution and keyword integration
|
|
5
|
+
Author: Apo
|
|
6
|
+
Author-email: Keycase Team <support@keycase.io>
|
|
7
|
+
Maintainer-email: Keycase Team <support@keycase.io>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/TharassKeycase/keycase-python-sdk
|
|
10
|
+
Project-URL: Documentation, https://docs.keycase.io/python-agent
|
|
11
|
+
Project-URL: Repository, https://github.com/TharassKeycase/keycase-python-sdk
|
|
12
|
+
Project-URL: Issues, https://github.com/TharassKeycase/keycase-python-sdk/issues
|
|
13
|
+
Project-URL: Changelog, https://github.com/TharassKeycase/keycase-python-sdk/blob/main/CHANGELOG.md
|
|
14
|
+
Keywords: automation,testing,keyword-driven,test-automation,sdk,agent
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Topic :: Software Development :: Testing
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: requests>=2.31.0
|
|
31
|
+
Requires-Dist: websocket-client>=1.7.0
|
|
32
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
38
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
40
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
42
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: types-requests>=2.31.0; extra == "dev"
|
|
44
|
+
Dynamic: author
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
Dynamic: requires-python
|
|
47
|
+
|
|
48
|
+
# Keycase Python Agent
|
|
49
|
+
|
|
50
|
+
A professional Python SDK for Keycase Agent execution and keyword integration. This agent connects to the Keycase automation platform to execute keyword-based automation flows.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **WebSocket Communication**: Real-time connection to Keycase server
|
|
55
|
+
- **Local Execution Mode**: Run execution plans locally without server connection
|
|
56
|
+
- **Plugin Architecture**: Extensible keyword system with auto-discovery
|
|
57
|
+
- **Robust Execution**: Threaded execution with graceful shutdown
|
|
58
|
+
- **Automatic Reconnection**: Exponential backoff with circuit breaker pattern
|
|
59
|
+
- **Token Management**: Automatic token refresh before expiry
|
|
60
|
+
- **Type Safety**: Full type hints throughout codebase
|
|
61
|
+
- **Cross-Platform**: Works on Windows, macOS, and Linux
|
|
62
|
+
|
|
63
|
+
## Prerequisites
|
|
64
|
+
|
|
65
|
+
### Python Version
|
|
66
|
+
|
|
67
|
+
- **Python 3.8 or higher** is required
|
|
68
|
+
|
|
69
|
+
Check your Python version:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python --version
|
|
73
|
+
# or
|
|
74
|
+
python3 --version
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Platform-Specific Setup
|
|
78
|
+
|
|
79
|
+
<details>
|
|
80
|
+
<summary><strong>Windows</strong></summary>
|
|
81
|
+
|
|
82
|
+
1. **Install Python** from [python.org](https://www.python.org/downloads/windows/) or via Windows Store
|
|
83
|
+
|
|
84
|
+
2. **Verify pip is installed**:
|
|
85
|
+
```cmd
|
|
86
|
+
python -m pip --version
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
3. **(Recommended) Create a virtual environment**:
|
|
90
|
+
```cmd
|
|
91
|
+
python -m venv venv
|
|
92
|
+
venv\Scripts\activate
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
4. **Install the package**:
|
|
96
|
+
```cmd
|
|
97
|
+
pip install -e .
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
</details>
|
|
101
|
+
|
|
102
|
+
<details>
|
|
103
|
+
<summary><strong>macOS</strong></summary>
|
|
104
|
+
|
|
105
|
+
1. **Install Python** (if not already installed):
|
|
106
|
+
```bash
|
|
107
|
+
# Using Homebrew (recommended)
|
|
108
|
+
brew install python@3.11
|
|
109
|
+
|
|
110
|
+
# Or download from python.org
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
2. **(Recommended) Create a virtual environment**:
|
|
114
|
+
```bash
|
|
115
|
+
python3 -m venv venv
|
|
116
|
+
source venv/bin/activate
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
3. **Install the package**:
|
|
120
|
+
```bash
|
|
121
|
+
pip install -e .
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
<details>
|
|
127
|
+
<summary><strong>Linux (Ubuntu/Debian)</strong></summary>
|
|
128
|
+
|
|
129
|
+
1. **Install Python and pip**:
|
|
130
|
+
```bash
|
|
131
|
+
sudo apt update
|
|
132
|
+
sudo apt install python3 python3-pip python3-venv
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
2. **(Recommended) Create a virtual environment**:
|
|
136
|
+
```bash
|
|
137
|
+
python3 -m venv venv
|
|
138
|
+
source venv/bin/activate
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
3. **Install the package**:
|
|
142
|
+
```bash
|
|
143
|
+
pip install -e .
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
<details>
|
|
149
|
+
<summary><strong>Linux (RHEL/CentOS/Fedora)</strong></summary>
|
|
150
|
+
|
|
151
|
+
1. **Install Python and pip**:
|
|
152
|
+
```bash
|
|
153
|
+
# Fedora
|
|
154
|
+
sudo dnf install python3 python3-pip
|
|
155
|
+
|
|
156
|
+
# RHEL/CentOS 8+
|
|
157
|
+
sudo dnf install python39 python39-pip
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
2. **(Recommended) Create a virtual environment**:
|
|
161
|
+
```bash
|
|
162
|
+
python3 -m venv venv
|
|
163
|
+
source venv/bin/activate
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
3. **Install the package**:
|
|
167
|
+
```bash
|
|
168
|
+
pip install -e .
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
</details>
|
|
172
|
+
|
|
173
|
+
## Installation
|
|
174
|
+
|
|
175
|
+
### Quick Start
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Clone the repository
|
|
179
|
+
git clone https://github.com/TharassKeycase/keycase-python-sdk.git
|
|
180
|
+
cd keycase-python-sdk
|
|
181
|
+
|
|
182
|
+
# Create and activate virtual environment
|
|
183
|
+
python3 -m venv venv
|
|
184
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
185
|
+
|
|
186
|
+
# Install the package
|
|
187
|
+
pip install -e .
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Development Installation
|
|
191
|
+
|
|
192
|
+
For development with testing and code quality tools:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
pip install -e ".[dev]"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
This installs additional dependencies: pytest, black, isort, mypy, flake8, and more.
|
|
199
|
+
|
|
200
|
+
## Configuration
|
|
201
|
+
|
|
202
|
+
The agent uses AgentToken-based authentication. Get your AgentToken from the Keycase platform.
|
|
203
|
+
|
|
204
|
+
### Required Environment Variables
|
|
205
|
+
|
|
206
|
+
| Variable | Description | Example |
|
|
207
|
+
|----------|-------------|---------|
|
|
208
|
+
| `HTTP_URL` | HTTP API base URL | `http://localhost:3000/api` |
|
|
209
|
+
| `AGENT_TOKEN` | AgentToken from platform (must start with `agt_`) | `agt_NW6KGfsl3Re...` |
|
|
210
|
+
| `AGENT_NAME` | Unique agent name within organization | `my-agent-01` |
|
|
211
|
+
|
|
212
|
+
### Optional Environment Variables
|
|
213
|
+
|
|
214
|
+
| Variable | Description | Example |
|
|
215
|
+
|----------|-------------|---------|
|
|
216
|
+
| `AGENT_VERSION` | Agent version | `1.0.0` |
|
|
217
|
+
| `AGENT_CAPABILITIES` | Comma-separated list of capabilities | `selenium,api` |
|
|
218
|
+
| `AGENT_TAGS` | Comma-separated tags for categorization | `production,windows` |
|
|
219
|
+
|
|
220
|
+
> **Note:** The WebSocket URL (`wsUrl`) and Agent ID (`agentId`) are now returned dynamically from the authentication response. You no longer need to configure these manually.
|
|
221
|
+
|
|
222
|
+
### Setting Environment Variables
|
|
223
|
+
|
|
224
|
+
<details>
|
|
225
|
+
<summary><strong>Windows (Command Prompt)</strong></summary>
|
|
226
|
+
|
|
227
|
+
```cmd
|
|
228
|
+
set HTTP_URL=http://localhost:3000/api
|
|
229
|
+
set AGENT_TOKEN=agt_your_token_here
|
|
230
|
+
set AGENT_NAME=my-agent-01
|
|
231
|
+
set AGENT_VERSION=1.0.0
|
|
232
|
+
set AGENT_CAPABILITIES=selenium,api
|
|
233
|
+
set AGENT_TAGS=production,windows
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
</details>
|
|
237
|
+
|
|
238
|
+
<details>
|
|
239
|
+
<summary><strong>Windows (PowerShell)</strong></summary>
|
|
240
|
+
|
|
241
|
+
```powershell
|
|
242
|
+
$env:HTTP_URL = "http://localhost:3000/api"
|
|
243
|
+
$env:AGENT_TOKEN = "agt_your_token_here"
|
|
244
|
+
$env:AGENT_NAME = "my-agent-01"
|
|
245
|
+
$env:AGENT_VERSION = "1.0.0"
|
|
246
|
+
$env:AGENT_CAPABILITIES = "selenium,api"
|
|
247
|
+
$env:AGENT_TAGS = "production,windows"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
</details>
|
|
251
|
+
|
|
252
|
+
<details>
|
|
253
|
+
<summary><strong>macOS / Linux</strong></summary>
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
export HTTP_URL="http://localhost:3000/api"
|
|
257
|
+
export AGENT_TOKEN="agt_your_token_here"
|
|
258
|
+
export AGENT_NAME="my-agent-01"
|
|
259
|
+
export AGENT_VERSION="1.0.0"
|
|
260
|
+
export AGENT_CAPABILITIES="selenium,api"
|
|
261
|
+
export AGENT_TAGS="production,windows"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Or create a `.env` file in the project root:
|
|
265
|
+
|
|
266
|
+
```env
|
|
267
|
+
HTTP_URL=http://localhost:3000/api
|
|
268
|
+
AGENT_TOKEN=agt_your_token_here
|
|
269
|
+
AGENT_NAME=my-agent-01
|
|
270
|
+
AGENT_VERSION=1.0.0
|
|
271
|
+
AGENT_CAPABILITIES=selenium,api
|
|
272
|
+
AGENT_TAGS=production,windows
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
</details>
|
|
276
|
+
|
|
277
|
+
## Usage
|
|
278
|
+
|
|
279
|
+
### Command Line
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Start the agent (uses environment variables)
|
|
283
|
+
keycase-agent
|
|
284
|
+
|
|
285
|
+
# Or run directly
|
|
286
|
+
python main.py
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Programmatic Usage
|
|
290
|
+
|
|
291
|
+
#### WebSocket Mode (Server Connection)
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from keycase_agent import KeycaseAgent, load_config, load_keywords
|
|
295
|
+
|
|
296
|
+
# Load keywords from directory
|
|
297
|
+
load_keywords()
|
|
298
|
+
|
|
299
|
+
# Load configuration from environment
|
|
300
|
+
config = load_config()
|
|
301
|
+
|
|
302
|
+
# Create and start agent
|
|
303
|
+
agent = KeycaseAgent(config)
|
|
304
|
+
agent.start()
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### Local Mode (Standalone Execution)
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from keycase_agent import ExecutionManager, load_keywords
|
|
311
|
+
|
|
312
|
+
# Load keywords
|
|
313
|
+
load_keywords('path/to/keywords')
|
|
314
|
+
|
|
315
|
+
# Create manager in local mode
|
|
316
|
+
manager = ExecutionManager(mode='local')
|
|
317
|
+
|
|
318
|
+
# Execute plan (dict or JSON string)
|
|
319
|
+
execution_plan = {
|
|
320
|
+
"keywordInstances": [...],
|
|
321
|
+
"flows": [...]
|
|
322
|
+
}
|
|
323
|
+
results = manager.execute_local(execution_plan)
|
|
324
|
+
|
|
325
|
+
print(results)
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
See [LOCAL_EXECUTION.md](LOCAL_EXECUTION.md) for complete local mode documentation.
|
|
329
|
+
|
|
330
|
+
## Creating Custom Keywords
|
|
331
|
+
|
|
332
|
+
Keywords are Python functions decorated with `@keyword`. You can also annotate parameters with `@param`, `@input_param`, and `@output_param` for documentation and validation.
|
|
333
|
+
|
|
334
|
+
### Basic Keyword
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
from keycase_agent import keyword
|
|
338
|
+
|
|
339
|
+
@keyword("Add Numbers")
|
|
340
|
+
def add_numbers(a: int, b: int) -> dict:
|
|
341
|
+
"""Add two numbers together."""
|
|
342
|
+
return {"sum": a + b}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Keyword with Parameter Annotations
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
from keycase_agent import keyword, input_param, output_param
|
|
349
|
+
|
|
350
|
+
@keyword("Calculate Sum")
|
|
351
|
+
@input_param("a", type="number", required=True, description="First number")
|
|
352
|
+
@input_param("b", type="number", required=True, description="Second number")
|
|
353
|
+
@output_param("sum", type="number", description="The sum of a and b")
|
|
354
|
+
@output_param("product", type="number", description="The product of a and b")
|
|
355
|
+
def calculate(a: float, b: float) -> dict:
|
|
356
|
+
"""Calculate sum and product of two numbers."""
|
|
357
|
+
return {
|
|
358
|
+
"sum": a + b,
|
|
359
|
+
"product": a * b,
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Parameter Decorator Options
|
|
364
|
+
|
|
365
|
+
| Option | Type | Description | Status |
|
|
366
|
+
|--------|------|-------------|--------|
|
|
367
|
+
| `name` | str | Parameter name (must match function argument for inputs) | Supported |
|
|
368
|
+
| `direction` | str | `"input"` or `"output"` | Supported |
|
|
369
|
+
| `default` | any | Default value if not provided | Supported |
|
|
370
|
+
| `description` | str | Human-readable description | Supported |
|
|
371
|
+
| `choices` | list | List of allowed values (for dropdowns) | Supported |
|
|
372
|
+
| `type` | str | Parameter type (`"string"`, `"number"`, etc.) | Planned |
|
|
373
|
+
| `required` | bool | Whether the parameter is required | Planned |
|
|
374
|
+
|
|
375
|
+
> **Note:** Options marked as "Planned" are accepted by the SDK for forward compatibility
|
|
376
|
+
> but are not yet enforced by the Keycase platform. They will be fully supported in a future release.
|
|
377
|
+
> See [ROADMAP.md](ROADMAP.md) for details.
|
|
378
|
+
|
|
379
|
+
### Parameter with Choices (Dropdown)
|
|
380
|
+
|
|
381
|
+
```python
|
|
382
|
+
@keyword("Set Log Level")
|
|
383
|
+
@input_param("level", type="string", required=True,
|
|
384
|
+
description="Logging level",
|
|
385
|
+
choices=["DEBUG", "INFO", "WARNING", "ERROR"])
|
|
386
|
+
def set_log_level(level: str) -> dict:
|
|
387
|
+
return {"status": "ok"}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Getting Keyword Schemas
|
|
391
|
+
|
|
392
|
+
You can retrieve the schema for documentation or UI generation:
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
from keycase_agent import get_keyword_schema, get_all_keyword_schemas
|
|
396
|
+
|
|
397
|
+
# Get schema for a specific keyword
|
|
398
|
+
schema = get_keyword_schema(calculate)
|
|
399
|
+
print(schema)
|
|
400
|
+
# {
|
|
401
|
+
# "name": "Calculate Sum",
|
|
402
|
+
# "function": "calculate",
|
|
403
|
+
# "params": [
|
|
404
|
+
# {"name": "a", "direction": "input", "type": "number", "required": true, ...},
|
|
405
|
+
# ...
|
|
406
|
+
# ]
|
|
407
|
+
# }
|
|
408
|
+
|
|
409
|
+
# Get all registered keyword schemas
|
|
410
|
+
all_schemas = get_all_keyword_schemas()
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Place your keyword files in a folder and load them with `load_keywords('your_folder')`.
|
|
414
|
+
|
|
415
|
+
See the `examples/` folder for sample keyword implementations.
|
|
416
|
+
|
|
417
|
+
## Architecture
|
|
418
|
+
|
|
419
|
+
```
|
|
420
|
+
┌─────────────────────────────────────────────────────────┐
|
|
421
|
+
│ KeycaseAgent │
|
|
422
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
|
|
423
|
+
│ │ AuthService │ │ WebSocket │ │ ExecutionManager│ │
|
|
424
|
+
│ │ │ │ Client │ │ │ │
|
|
425
|
+
│ └─────────────┘ └─────────────┘ └─────────────────┘ │
|
|
426
|
+
│ │ │ │ │
|
|
427
|
+
│ └────────────────┼──────────────────┘ │
|
|
428
|
+
│ │ │
|
|
429
|
+
│ ┌───────▼───────┐ │
|
|
430
|
+
│ │ Keyword │ │
|
|
431
|
+
│ │ Registry │ │
|
|
432
|
+
│ └───────────────┘ │
|
|
433
|
+
└─────────────────────────────────────────────────────────┘
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Core Components
|
|
437
|
+
|
|
438
|
+
| Component | Description |
|
|
439
|
+
|-----------|-------------|
|
|
440
|
+
| **KeycaseAgent** | Main orchestrator managing connections and execution |
|
|
441
|
+
| **ExecutionManager** | Handles threaded execution of keyword flows |
|
|
442
|
+
| **AuthService** | Manages authentication and automatic token refresh |
|
|
443
|
+
| **WebSocketClient** | Handles real-time communication with reconnection |
|
|
444
|
+
| **KeywordRegistry** | Stores and retrieves registered keyword functions |
|
|
445
|
+
|
|
446
|
+
## Development
|
|
447
|
+
|
|
448
|
+
### Running Tests
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
# Run all tests
|
|
452
|
+
pytest
|
|
453
|
+
|
|
454
|
+
# Run with coverage report
|
|
455
|
+
pytest --cov=keycase_agent --cov-report=html
|
|
456
|
+
|
|
457
|
+
# Run specific test file
|
|
458
|
+
pytest tests/test_execution_manager.py -v
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Code Quality
|
|
462
|
+
|
|
463
|
+
```bash
|
|
464
|
+
# Format code
|
|
465
|
+
black keycase_agent/
|
|
466
|
+
|
|
467
|
+
# Sort imports
|
|
468
|
+
isort keycase_agent/
|
|
469
|
+
|
|
470
|
+
# Type checking
|
|
471
|
+
mypy keycase_agent/
|
|
472
|
+
|
|
473
|
+
# Linting
|
|
474
|
+
flake8 keycase_agent/
|
|
475
|
+
|
|
476
|
+
# Run all checks
|
|
477
|
+
black keycase_agent/ && isort keycase_agent/ && mypy keycase_agent/ && flake8 keycase_agent/
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### Building Distribution
|
|
481
|
+
|
|
482
|
+
```bash
|
|
483
|
+
# Install build tools
|
|
484
|
+
pip install build
|
|
485
|
+
|
|
486
|
+
# Build package
|
|
487
|
+
python -m build
|
|
488
|
+
|
|
489
|
+
# Install built package
|
|
490
|
+
pip install dist/keycase_agent_sdk-0.1.0-py3-none-any.whl
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
## Troubleshooting
|
|
494
|
+
|
|
495
|
+
### Common Issues
|
|
496
|
+
|
|
497
|
+
<details>
|
|
498
|
+
<summary><strong>"No module named 'keycase_agent'"</strong></summary>
|
|
499
|
+
|
|
500
|
+
Make sure you've installed the package:
|
|
501
|
+
```bash
|
|
502
|
+
pip install -e .
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
If using a virtual environment, ensure it's activated.
|
|
506
|
+
|
|
507
|
+
</details>
|
|
508
|
+
|
|
509
|
+
<details>
|
|
510
|
+
<summary><strong>"Connection refused" or WebSocket errors</strong></summary>
|
|
511
|
+
|
|
512
|
+
1. Verify the Keycase server is running
|
|
513
|
+
2. Check `HTTP_URL` is correct
|
|
514
|
+
3. Ensure no firewall is blocking the connection
|
|
515
|
+
4. The WebSocket URL is returned from authentication - verify the server is returning a valid `wsUrl`
|
|
516
|
+
|
|
517
|
+
</details>
|
|
518
|
+
|
|
519
|
+
<details>
|
|
520
|
+
<summary><strong>"Authentication failed"</strong></summary>
|
|
521
|
+
|
|
522
|
+
1. Verify `AGENT_TOKEN` is correct and starts with `agt_`
|
|
523
|
+
2. Check the token has not been revoked on the platform
|
|
524
|
+
3. Ensure `AGENT_NAME` is unique within your organization
|
|
525
|
+
4. Verify the token has the correct permissions
|
|
526
|
+
|
|
527
|
+
</details>
|
|
528
|
+
|
|
529
|
+
<details>
|
|
530
|
+
<summary><strong>Keywords not found</strong></summary>
|
|
531
|
+
|
|
532
|
+
1. Ensure keywords are in the `keywords/` directory
|
|
533
|
+
2. Check the `@keyword` decorator is applied
|
|
534
|
+
3. Verify keyword names match the execution plan
|
|
535
|
+
|
|
536
|
+
</details>
|
|
537
|
+
|
|
538
|
+
## License
|
|
539
|
+
|
|
540
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
541
|
+
|
|
542
|
+
## Support
|
|
543
|
+
|
|
544
|
+
- **Documentation**: [docs.keycase.io](https://docs.keycase.io)
|
|
545
|
+
- **Issues**: [GitHub Issues](https://github.com/TharassKeycase/keycase-python-sdk/issues)
|
|
546
|
+
- **Email**: support@keycase.io
|