mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-29 17:09:31 +00:00
feat(ptc): programmatic tool calling -- executor, SDK, and E2E tests
Add ToolExecutor for standalone tool dispatch used by both the
orchestrator HTTP RPC endpoint and the WASM tool_invoke host function.
Includes Python SDK for container scripts, WASM test fixture, and
comprehensive E2E test coverage across all PTC paths.
Implementation:
- ToolExecutor with timeout, nesting depth limit, safety sanitization
- Orchestrator POST /worker/{job_id}/tools/call endpoint with SSE events
- WASM tool_invoke host function with alias resolution
- Python SDK (stdlib-only) with call_tool + convenience wrappers
Tests (16 new):
- 6 orchestrator HTTP RPC tests (auth, echo, not-found, timeout, SSE, no-executor)
- 3 executor integration tests (sanitization, invalid params, sequential)
- 4 Python SDK tests (env vars, request format, HTTP error, wrappers)
- 3 WASM E2E tests (echo via alias, alias not granted, no capability)
Refs #407
Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "test-ptc-tool"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
wit-bindgen = "0.41.0"
|
||||
serde_json = "1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
||||
lto = true
|
||||
strip = true
|
||||
codegen-units = 1
|
||||
|
||||
[workspace]
|
||||
@@ -0,0 +1,52 @@
|
||||
wit_bindgen::generate!({
|
||||
world: "sandboxed-tool",
|
||||
path: "../../wit/tool.wit",
|
||||
});
|
||||
|
||||
struct TestPtcTool;
|
||||
|
||||
impl exports::near::agent::tool::Guest for TestPtcTool {
|
||||
fn execute(req: exports::near::agent::tool::Request) -> exports::near::agent::tool::Response {
|
||||
match execute_inner(&req.params) {
|
||||
Ok(result) => exports::near::agent::tool::Response {
|
||||
output: Some(result),
|
||||
error: None,
|
||||
},
|
||||
Err(e) => exports::near::agent::tool::Response {
|
||||
output: None,
|
||||
error: Some(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn schema() -> String {
|
||||
r#"{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}"#.to_string()
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
"Test tool for PTC: calls echo via tool_invoke".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_inner(params: &str) -> Result<String, String> {
|
||||
let parsed: serde_json::Value = serde_json::from_str(params)
|
||||
.map_err(|e| format!("Invalid params: {}", e))?;
|
||||
|
||||
let message = parsed.get("message")
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or("Missing 'message' parameter")?;
|
||||
|
||||
// Build the parameters for the echo tool
|
||||
let echo_params = serde_json::json!({"message": message});
|
||||
|
||||
// Call tool_invoke with alias "echo_alias" which should resolve to "echo"
|
||||
let result = near::agent::host::tool_invoke(
|
||||
"echo_alias",
|
||||
&echo_params.to_string(),
|
||||
)?;
|
||||
|
||||
// Prefix to prove it went through WASM
|
||||
Ok(format!("via_wasm:{}", result))
|
||||
}
|
||||
|
||||
export!(TestPtcTool);
|
||||
Reference in New Issue
Block a user