Skip to content
中文

Synchronous execution adapter for host-selected invocations ​

Record start, completion, and failure uniformly for synchronous invocations the host has already selected, without replacing tool selection or authorization.

executeInvocation returns void; results are expressed through the App's own Context and an optional receipt port. handler.call must be synchronous and must not secretly return a Promise. Selection, authorization facts, argument structure, and side effects still belong to the host.

When asynchronous values and a unified ToolResult are needed, prefer the ToolRegistry/Support tool runtime. This synchronous adapter mainly connects existing host invocation flows; do not build a separate InvocationHandler framework for all tools. journal/diagnostics/signal/checkpoint/receipt can be configured, and they are all App implementations of existing contracts.

Progressive examples for the same business case ​

Execute a local invocation the App has already selected ​

Beginner · Node.js

ts
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) {
  context.status = '服务正常';
} }, {}, state);
console.log(state.status);
js
import { executeInvocation } from '@jangts/agent-core/tools';
const state = { status: '' };
executeInvocation({ id: 'read-status', call(_input, context) {
        context.status = '服务正常';
    } }, {}, state);
console.log(state.status);

Connect the same request journal and cancellation signal ​

Configuration · Node.js

ts
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input: {}, context: typeof state) { context.status = '服务正常'; } }, {}, state, {
  signal: context => context.signal,
  journal: context => context.journal,
  receipt: context => context.status,
});
console.log(state.journal.snapshot());
js
import { executeInvocation } from '@jangts/agent-core/tools';
import { ContextJournal } from '@jangts/agent-core/journal';
const state = { status: '', journal: new ContextJournal(), signal: new AbortController().signal };
executeInvocation({ id: 'read-status', call(_input, context) { context.status = '服务正常'; } }, {}, state, {
    signal: context => context.signal,
    journal: context => context.journal,
    receipt: context => context.status,
});
console.log(state.journal.snapshot());

Policies & implementations ​

API reference, usage examples and developer guides.