JamJet

Agent-as-Tool

Wrap any agent as a callable tool — sync, streaming, or conversational.

Agent-as-Tool

JamJet lets you wrap any agent as a callable tool inside a workflow. Three invocation modes cover different use cases — from quick lookups to long-running analyses to multi-turn conversations.

Three Modes

Sync

Single request, single response. Best for fast, stateless operations.

graph.add_agent_tool("classifier",
    agent="https://classifier-agent.example.com",
    mode="sync",
    timeout_ms=5000,
)

Posts to /tasks/send and returns the full response as the node output.

Streaming

Incremental NDJSON processing with real-time event emission. Best for long-running agents where you want progress visibility, budget control, and early termination.

graph.add_agent_tool("researcher",
    agent="https://research-agent.example.com",
    mode="streaming",
    budget={"max_cost_usd": 0.50},
    streaming={"idle_timeout_secs": 30},
)

Posts to /tasks/sendSubscribe and processes the NDJSON stream incrementally:

  • Real-time events — each chunk is emitted to the state backend as it arrives, not batched at the end
  • Idle timeout — if no data arrives within idle_timeout_secs (default 30), the stream is terminated
  • Budget guard — when accumulated cost_usd from chunks exceeds max_cost_usd, the stream stops
  • A2A cancel — on early termination (budget or timeout), a best-effort tasks/cancel is sent to the remote agent
  • Partial results preserved — chunks already emitted are never lost, even on failure

Conversational

Multi-turn exchange for iterative refinement. The coordinator sends input, reads the response, and feeds it back as the next turn's input.

graph.add_agent_tool("editor",
    agent="https://editor-agent.example.com",
    mode={"conversational": {"max_turns": 5}},
)

Posts to /tasks/send in a loop. Stops when the agent responds with status: "completed" or max_turns is reached.

Streaming Configuration

ParameterDefaultDescription
streaming.idle_timeout_secs30Seconds of silence before terminating
budget.max_cost_usdNoneMaximum accumulated cost before termination
timeout_ms30000Overall HTTP timeout (sync/conversational only)

For streaming mode, the per-chunk idle timeout replaces the overall HTTP timeout. The client is built without a global timeout so long-running streams with active data aren't killed prematurely.

Events

The agent tool emits structured events to the event log:

EventWhen
agent_tool_invokedRequest sent to remote agent
agent_tool_progressEach NDJSON chunk received (streaming only)
agent_tool_completedSuccessful completion with final output
agent_tool_terminatedEarly termination (budget exceeded or idle timeout)
agent_tool_errorNetwork error mid-stream

Each event includes timestamp_ms for precise timing. Progress events include chunk_index and accumulated_cost_usd.

Error Handling

FailureBehavior
Network error mid-streamNode fails with error, partial results preserved
Malformed JSON in NDJSONWrapped as {"raw": "..."}, stream continues
Non-UTF8 dataSkipped with warning, stream continues
Idle timeoutNode fails, A2A cancel sent
Budget exceededNode fails, A2A cancel sent
Agent returns HTTP errorNode fails immediately

Hard failures (timeout, network error) cause the node to fail so the workflow can retry or handle the error. Budget breach is also treated as a failure.

Protocol Resolution

The agent URI determines the protocol:

URI prefixProtocol
https://A2A (remote HTTP)
jamjet://Local (in-process)
OtherMCP

Example

See the agent-as-tool example for a complete workflow using all three modes.

On this page