Documentation
¶
Overview ¶
Package clientcalls tracks tool calls a client is executing.
The Realtime protocol puts tool execution on the client: the server emits the call, the client runs it, and the result comes back as an ordinary conversation item. So between those two moments a session is holding an invocation it does not control, and the model is looking at a call with no result.
A batch is committed only when every call in it has a result, because a partial batch would leave the model unable to tell whether the rest is coming. That is correct, and on its own it means a client that crashes, disconnects mid-call, or simply never answers leaves the invocation outstanding for the life of the session - the conversation keeps working, but that branch of it never advances again, and nothing anywhere says so.
So an invocation has a deadline. When it passes, the calls that were never answered get results saying so, the batch commits, and the session carries on with a model that knows the tools failed rather than one still waiting. A timeout is not a good outcome, but it is an outcome, and a stuck invocation is not.
Three bindings need this and had three copies of the bookkeeping. It is one package because the deadline is the part that is easy to get subtly wrong, and because a fix that lands in one copy of something is a fix that has not landed.
Index ¶
- Constants
- type Config
- type Tracker
- func (tracker *Tracker) Close()
- func (tracker *Tracker) Hold(invocationID string, results []trajectory.ToolResult)
- func (tracker *Tracker) Outstanding() int
- func (tracker *Tracker) Result(result trajectory.ToolResult) error
- func (tracker *Tracker) Track(invocationID string, calls []trajectory.ToolCall) error
Constants ¶
const DefaultTimeout = 2 * time.Minute
DefaultTimeout bounds an invocation when a binding does not say otherwise.
It matches the provider request timeout, because the two answer the same question - how long the session waits on something outside it before deciding it is not coming - and answering it differently in two places would be a distinction without a reason.
A client with work that legitimately runs longer than this returns a result saying the work started and reports the outcome as a message when it finishes. That keeps the model's view accurate at every moment, which holding the batch open does not.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Timeout bounds one invocation. Zero selects DefaultTimeout; a negative
// value disables the deadline, which is what a harness driving tool
// results by hand wants and is never right for a session facing a real
// client.
Timeout time.Duration
// Scheduler supplies the deadline. Nil selects the system clock.
Scheduler clock.Scheduler
// Commit appends a complete batch, in call order. It is called with no
// lock held, so it may re-enter the tracker.
Commit func(invocationID string, results []trajectory.ToolResult) error
// Expired reports an invocation the client never finished answering,
// after its synthesised results have been committed. It exists so the
// session can tell the client what happened rather than leaving the
// timeout as something only the model can see.
Expired func(invocationID string, unanswered []trajectory.ToolCall)
}
Config configures a tracker.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker holds invocations a client has not finished answering.
func (*Tracker) Close ¶
func (tracker *Tracker) Close()
Close stops every outstanding deadline.
It does not commit anything: the session is ending, and a batch appended to a trajectory nobody will read again is not worth the risk of running a commit against a runtime that is shutting down.
func (*Tracker) Hold ¶
func (tracker *Tracker) Hold(invocationID string, results []trajectory.ToolResult)
Hold records results this process produced for a split batch.
They are not enough to complete anything on their own: the invocation is waiting on the client's half, and holding these is what lets both commit together when it arrives.
func (*Tracker) Outstanding ¶
Outstanding reports how many invocations are waiting on a client. It exists for tests and for operational visibility into a session that is stuck.
func (*Tracker) Result ¶
func (tracker *Tracker) Result(result trajectory.ToolResult) error
Result records one client-executed result and commits the batch when it is the last one outstanding.
func (*Tracker) Track ¶
func (tracker *Tracker) Track(invocationID string, calls []trajectory.ToolCall) error
Track registers an invocation and starts its deadline.
Every call in the batch is registered, including any this process is executing itself: a split batch commits as one thing, so the local results wait alongside the client's and the deadline covers the whole of it.