Tools

Test Lambda tool without creation

Tests a Lambda tool without creating it.

Use this to:

  • Validate Python code syntax and security constraints
  • Discover input/output schemas from type annotations
  • Test execution with sample input
  • Verify schema compatibility
  • Exercise the lambda tool's tool_configurations with a stand-in test_context that supplies the agent metadata, secrets, and session metadata its $refs resolve against

The function runs in the same secure sandbox environment as production tools.

post/v2/tools/test

Headers

Request-Timeoutinteger

The platform makes a best effort to complete the request in the specified seconds, or it times out.

Request-Timeout-Millisinteger

The platform makes a best effort to complete the request in the specified milliseconds, or it times out.

Request body

language'python'

The programming language. Currently only 'python' (Python 3.12) is supported.

codestring required

The Python 3.12 code for the function. Must define a process() entry point. Object parameters must use TypedDict; validation rejects bare dict and Dict[K, V] parameters. See the code field on CreateLambdaToolRequest for full details and examples.

test_inputobject required

The input parameters to test the function with. The platform validates them against the discovered input schema.

timeout_secondsinteger

Maximum execution time in seconds for this test. Overrides execution_configuration if specified. When omitted, the supplied execution_configuration timeout applies in full — up to 21600 seconds — and a request with none runs at 30 seconds. A budget longer than 300 seconds requires stream_response to be true; a non-streaming request with a larger budget is rejected.

stream_responseboolean

When true, the response is streamed as Server-sent Events. While the test runs the platform sends zero or more heartbeat events, then exactly one terminal result event carrying the same object the non-streaming response returns. A platform failure after the stream has started closes the connection without a result.

tool_configurationsobject

Named configurations of other tools the code under test may invoke through its built-in tool module. See the tool_configurations field on CreateLambdaToolRequest for semantics and constraints.

Example request

{
  "language": "python",
  "code": "def process(order_count: int, total_revenue: float) -> dict:\n    score = order_count * 10 + total_revenue * 0.1\n    return {'score': round(score, 2)}\n",
  "execution_configuration": {
    "max_execution_time_seconds": 30,
    "max_memory_mb": 100
  },
  "test_input": {
    "order_count": 10,
    "total_revenue": 500
  },
  "timeout_seconds": 10,
  "test_context": {
    "agent": {
      "metadata": {
        "ticket_api_base": "https://tickets.example.com/api/v1/"
      },
      "secrets": {
        "ticket_api_token": "test-token"
      }
    },
    "session": {
      "metadata": {
        "tenant_corpus": "kb"
      }
    }
  }
}

Response

The validation and execution results, or the streamed events when stream_response is true.

input_schemaobject

The discovered input schema from type annotations. May be null if validation failed or the code has no type hints.

output_schemaobject

The discovered output schema from type annotations. May be null if validation failed or the code has no type hints.

Example response

{
  "validation": {
    "status": "valid",
    "errors": [
      "Line 5: Use of forbidden module 'os'"
    ]
  },
  "input_schema": {
    "type": "object",
    "properties": {
      "order_count": {
        "type": "integer"
      },
      "total_revenue": {
        "type": "number"
      }
    },
    "required": [
      "order_count",
      "total_revenue"
    ]
  },
  "output_schema": {
    "type": "object",
    "properties": {
      "score": {
        "type": "number"
      }
    }
  },
  "execution": {
    "success": true,
    "output": {
      "score": 105
    },
    "latency_millis": 125,
    "memory_used_mb": 32,
    "validation_results": {
      "input_valid": true,
      "output_valid": true,
      "validation_errors": []
    }
  }
}

Changes