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.

@FunctionalInterface public interface AgentFactory
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 Type
    Method
    Description
    io.agentscope.harness.agent.HarnessAgent
    Returns the agent for this run.
    fixed(io.agentscope.harness.agent.HarnessAgent agent)
    Factory that always returns the same agent, ignoring the request.
    of(Supplier<io.agentscope.harness.agent.HarnessAgent> supplier)
    Factory backed by a supplier, ignoring the request.
  • Method Details

    • create

      io.agentscope.harness.agent.HarnessAgent create(AgentRequest request)
      Returns the agent for this run. Must not return null; throw to fail the task with an error status instead.
    • fixed

      static AgentFactory fixed(io.agentscope.harness.agent.HarnessAgent agent)
      Factory that always returns the same agent, ignoring the request.
    • of

      static AgentFactory of(Supplier<io.agentscope.harness.agent.HarnessAgent> supplier)
      Factory backed by a supplier, ignoring the request.