Overview
Concrete tool for creating and finalizing traced call records provided by the Wandb Weave library.
Description
The WeaveClient.create_call() and WeaveClient.finish_call() methods manage the lifecycle of a Call object. create_call generates a unique call ID, captures inputs, resolves the parent from the thread-local call stack, and persists the call start. finish_call records the output or exception, computes summary statistics, and writes the finalized call to the backend.
The Call dataclass stores all execution metadata including trace_id, parent_id, inputs, output, timing, summary (with usage and status counts), and thread context.
Usage
These methods are invoked automatically by the @weave.op decorator. Use them directly only for advanced scenarios requiring manual call management, such as custom instrumentation of non-Python operations.
Code Reference
Source Location
- Repository: wandb/weave
- File: weave/trace/weave_client.py
- Lines: L643-792 (create_call), L860-1009 (finish_call)
- File: weave/trace/call.py
- Lines: L46-100 (Call dataclass)
Signature
def create_call(
self,
op: str | Op,
inputs: dict[str, Any],
parent: Call | None = None,
attributes: dict[str, Any] | None = None,
display_name: str | Callable[[Call], str] | None = None,
*,
use_stack: bool = True,
_call_id_override: str | None = None,
) -> Call:
"""Create, log, and push a call onto the runtime stack.
Args:
op: The operation producing the call, or the name of an anonymous operation.
inputs: The inputs to the operation.
parent: The parent call. If not provided, the current stack top is used.
display_name: The display name for the call.
attributes: The attributes for the call.
use_stack: Whether to push the call onto the runtime stack.
Returns:
The created Call object.
"""
def finish_call(
self,
call: Call,
output: Any = None,
exception: BaseException | None = None,
*,
op: Op | None = None,
) -> None:
"""Finalize a call and persist its results.
Values in call.summary are deep-merged with computed summary statistics.
"""
Import
from weave.trace.weave_client import WeaveClient
from weave.trace.call import Call
I/O Contract
Inputs (create_call)
| Name |
Type |
Required |
Description
|
| op |
Op |
Yes |
Operation or name of anonymous operation
|
| inputs |
dict[str, Any] |
Yes |
Input arguments to the operation
|
| parent |
None |
No |
Parent call (defaults to stack top)
|
| attributes |
None |
No |
Metadata attributes for the call
|
| display_name |
Callable | None |
No |
Display name in the UI
|
| use_stack |
bool |
No |
Push to runtime stack (default True)
|
Outputs (create_call)
| Name |
Type |
Description
|
| return |
Call |
Call object with id, trace_id, parent_id, inputs, started_at
|
Inputs (finish_call)
| Name |
Type |
Required |
Description
|
| call |
Call |
Yes |
The Call to finalize
|
| output |
Any |
No |
Return value of the operation
|
| exception |
None |
No |
Exception if the operation failed
|
| op |
None |
No |
The Op that produced the call
|
Outputs (finish_call)
| Name |
Type |
Description
|
| return |
None |
Side effect: persists call with output, ended_at, summary
|
Usage Examples
Manual Call Management
import weave
client = weave.init("my-team/my-project")
# Manually create a call
call = client.create_call(
op="my_custom_operation",
inputs={"query": "What is Weave?"},
attributes={"source": "manual"},
)
# ... perform the operation ...
result = {"answer": "Weave is an LLM observability framework"}
# Finalize the call
client.finish_call(call, output=result)
Related Pages
Implements Principle
Requires Environment
Uses Heuristic