Class GenkitAgentController

java.lang.Object
com.google.genkit.plugins.spring.GenkitAgentController

@RestController public class GenkitAgentController extends Object
REST controller that exposes Genkit agents (ActionType.AGENT bidi actions) as HTTP endpoints, at parity with the plugins/jetty module's AgentHandler / CompanionHandler.

For each registered agent named <name> this mounts, at the root path (NOT under /api/..., so that RemoteAgent/HttpAgentTransport clients that derive companion URLs by simple string concatenation on the base agent URL keep working regardless of which server plugin they talk to):

  • POST /<name> — one turn per request (non-streaming or SSE).
  • POST /<name>/getSnapshot — companion agent-snapshot action, if registered.
  • POST /<name>/abort — companion agent-abort action, if registered.

Actions are looked up by name at request time (mirroring GenkitFlowController.findFlowByName(java.lang.String)) rather than pre-registered per-agent handlers, since Spring MVC controllers use static @RequestMapping-family annotations.

  • Constructor Summary

    Constructors
    Constructor
    Description
    GenkitAgentController(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    Creates a new GenkitAgentController.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Object>
    abort(String agentName, com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
    Companion endpoint for aborting a pending agent session snapshot.
    org.springframework.http.ResponseEntity<Object>
    getSnapshot(String agentName, com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
    Companion endpoint for retrieving a previously-saved agent session snapshot.
    runAgent(String agentName, com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
    Handles one turn of an agent conversation.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GenkitAgentController

      public GenkitAgentController(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates a new GenkitAgentController.
      Parameters:
      objectMapper - the ObjectMapper for JSON serialization
  • Method Details

    • runAgent

      @PostMapping(value="/{agentName}", consumes="application/json") public Object runAgent(@PathVariable String agentName, @RequestBody(required=false) com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
      Handles one turn of an agent conversation. Non-streaming requests receive a single {"result": <output>} JSON body; requests that ask for streaming (via Accept: text/event-stream or ?stream=true) receive an SSE response instead — see streamAgent(java.lang.String, com.fasterxml.jackson.databind.JsonNode, jakarta.servlet.http.HttpServletRequest).
      Parameters:
      agentName - the name of the agent
      body - the request envelope: {"data": <AgentInput>, "init": <AgentInit>, "context": <optional map>}
      request - the servlet request, used to detect streaming
      Returns:
      the JSON result envelope, or an error envelope with a mapped HTTP status
    • getSnapshot

      @PostMapping(value="/{agentName}/getSnapshot", consumes="application/json") public org.springframework.http.ResponseEntity<Object> getSnapshot(@PathVariable String agentName, @RequestBody(required=false) com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
      Companion endpoint for retrieving a previously-saved agent session snapshot.
      Parameters:
      agentName - the name of the agent
      body - the request envelope: {"data": <input>, "context": <optional map>}
      request - the servlet request, whose headers are merged into the run's user context
      Returns:
      the JSON result envelope, or an error envelope with a mapped HTTP status
    • abort

      @PostMapping(value="/{agentName}/abort", consumes="application/json") public org.springframework.http.ResponseEntity<Object> abort(@PathVariable String agentName, @RequestBody(required=false) com.fasterxml.jackson.databind.JsonNode body, jakarta.servlet.http.HttpServletRequest request)
      Companion endpoint for aborting a pending agent session snapshot.
      Parameters:
      agentName - the name of the agent
      body - the request envelope: {"data": <input>, "context": <optional map>}
      request - the servlet request, whose headers are merged into the run's user context
      Returns:
      the JSON result envelope, or an error envelope with a mapped HTTP status