Interface AgentFactory
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Resolves the
HarnessAgent that executes an Agent Protocol task.
Called once per run — on the initial POST /tasks submission and again for every
POST /tasks/{id}/resume — with the full AgentRequest, including the submission
context map. Implementations may therefore route by agentId, tenant, or any
custom context attribute, and may build a fresh agent per task.
Register a bean of this type to override the default factory, which always returns the single
HarnessAgent bean:
@Bean
AgentFactory agentFactory(Map<String, HarnessAgent> agentsByName) {
return request -> agentsByName.getOrDefault(request.agentId(), agentsByName.get("default"));
}
For concurrent tasks, return a distinct instance per call (e.g. a prototype-scoped bean),
or configure the shared agent with checkRunning(false).
-
Method Summary
Modifier and TypeMethodDescriptionio.agentscope.harness.agent.HarnessAgentcreate(AgentRequest request) Returns the agent for this run.static AgentFactoryfixed(io.agentscope.harness.agent.HarnessAgent agent) Factory that always returns the same agent, ignoring the request.static AgentFactoryFactory backed by a supplier, ignoring the request.
-
Method Details
-
create
Returns the agent for this run. Must not returnnull; throw to fail the task with an error status instead. -
fixed
Factory that always returns the same agent, ignoring the request. -
of
Factory backed by a supplier, ignoring the request.
-