Skip to main content

Agent.execute() method

Executes a plugin method.

Normally, the execute() method need not be called. The agent will expose the plugin methods directly on the agent instance but this can be used when dynamically deciding which methods to call.

Signature:

execute<P = any, R = any>(method: string, args: P): Promise<R>;

Parameters

ParameterTypeDescription
methodstringmethod name
argsParguments object

Returns:

Promise<R>

Remarks

Plugin method will receive a context object as a second argument. Context object always has agent property that is the Agent instance that is executing said method

Example

await agent.execute('foo', { bar: 'baz' })

// is equivalent to:
await agent.foo({ bar: 'baz' })