Skip to content
Docs menu

Run tools with the agent

The call and answer loop, the tool runner, editor_context, needs_video and what to return from a tool.

Once tools are registered, you chat with the agent as usual and tell it you have tools. When a tool would help, the agent stops and asks you to run it. This page explains that loop and the SDK's runner, which does it for you.

The loop

Output
you ──chat (tools on)──────────────▶ agent
you ◀─────────── tool_call {tool_call_id, tool_name, arguments} ── agent   (the agent waits)
you run the tool in your app
you ──chat + client_tool_result {tool_call_id, result} ───────────▶ agent
you ◀──────────────────────────────── done {reply} ─────────────── agent   (or another tool_call)
  • **tool_call** is a stream event. It carries tool_call_id (an id to echo back), tool_name, arguments (matching the input_schema you registered) and files (files to download first, if the tool needs them).
  • **client_tool_result** is what you send back in the next chat turn of the same session: { "tool_call_id": "...", "result": { "success": true, "data": {...} } }. success is explicit and required: a result without it is not read as success. On failure send { "success": false, "error": "timeline is locked" }; the agent reads it and decides what to do.
  • The server never assumes a tool worked. It acts on the success you send.

Let the SDK do the loop

from falcore import Catalyst, ClientToolRunner, Param, Tool

catalyst = Catalyst()

runner = ClientToolRunner(catalyst, "sdk", editor_context=lambda: {"playhead": 12.0})
runner.add(
    Tool("place_clip", "Place an audio file on the timeline",
         params=[Param("file_id", "string", required=True), Param("start", "number", required=True)]),
    lambda call: {"track": 2, "offset": call.arguments["start"]},
)

# or with a decorator and a ready-made schema:
@runner.tool("add_marker", description="Add a marker", input_schema={"type": "object", "properties": {"at": {"type": "number"}}})
def add_marker(call):
    return {"ok": True}

answer = runner.run(message="Put a whoosh at 2.5 seconds")   # uses the client's session
print(answer.reply)

What the runner does, in order:

  1. Registers your tools for the session the run belongs to (the client's own unless you pass one), once per session, with mode="replace" so the set is exactly yours.
  2. Chats in that session with the tool set switched on, sending editor_context if you gave a function for it.
  3. Calls your function for every tool_call, with the arguments the agent chose, and sends back your return value as success: true, data: ....
  4. Reports failures. If your function raises (Python), throws (TypeScript) or returns Err (Rust), or the agent asked for a tool you did not register, the runner sends success: false with the message (up to 500 characters). It does not stop the run.
  5. Stops when the agent sends done, and returns the final answer. It also stops, with an error, after max_turns (default 25) in case the agent keeps asking.

What to return from a tool

You returnThe agent receives
A dict / objectsuccess: true, data = that object
Something else (a number, a string)success: true, data: {"value": ...}
Nothingsuccess: true, data: null
Raise / throw / Err(text)success: false, error = the text

Return what the agent needs to continue: where the clip landed, the new track number. It reads data.

editor_context: tell the agent about your editor

editor_context is a function returning a small object that is sent with every turn: the playhead, the selection, the frame rate. The agent uses it to choose sensible arguments ("put it at the playhead") without asking you.

When the agent needs a video

For a task about a video the agent may answer needs_video instead of a tool call. Give the runner a way to produce the file and it uploads once and repeats the message with the video attached.

answer = runner.run(message="Score this scene", upload_video=lambda: "scene.mp4")

Without that, the runner stops with a clear error saying the agent needs a video.

Doing the loop yourself

If you need full control (your own event loop), chat with the tool set on and handle the events:

with catalyst.chat.stream("Put a whoosh at 2.5 seconds", tools=True) as stream:
    for frame in stream:
        if frame.event == "tool_call":
            call = frame.data                                   # tool_call_id, tool_name, arguments
            result = {"success": True, "data": {"track": 2}}    # run it in your app

answer = catalyst.chat.create(client_tool_result={"tool_call_id": call["tool_call_id"], "result": result}, tools=True)

tools=True means "use this session's tools under the client's default name". To use a named set, pass client_id="premiere" instead. Either way the SDK sends the right <client>:<session> identifier, so the agent sees exactly the tools registered for this session.