instance

fun <T : Any> instance(agent: Agent, type: Class<T>): T

Run the agent instance as a subagent and return the result.

Parameters

agent

The agent instance to run as a subagent.

type

The expected return type.

IMPORTANT: This method always throws SubagentExecutionRequest internally. The framework catches this exception and uses it to execute the subagent. Any code written after this call in your action method will never execute. Use this call as the final statement in your action method, treating it like a return.

// WRONG — log.info will never run
Result r = RunSubagent.instance(myAgent, Result.class);
log.info("result: {}", r);
return r;

// CORRECT — this is the last statement
return RunSubagent.instance(myAgent, Result.class);

inline fun <T : Any> instance(instance: Agent): T