Class StateMachineTool

  • All Implemented Interfaces:
    com.embabel.agent.api.tool.Tool , com.embabel.agent.api.tool.ToolInfo , com.embabel.agent.api.tool.agentic.AgenticTool , com.embabel.agent.api.tool.agentic.ToolChaining , com.embabel.agent.api.tool.agentic.state.StateMachineToolOperations

    
    public final class StateMachineTool<S extends Enum<S>>
     implements AgenticTool<StateMachineTool<S>>, StateMachineToolOperations<S>
                        

    A tool that manages state transitions, with tools available based on the current state.

    Unlike com.embabel.agent.api.tool.playbook.PlaybookTool which uses unlock conditions, StateMachineTool uses explicit states defined by an enum. Tools are registered with specific states where they're available, and can trigger transitions to other states.

    enum class OrderState { DRAFT, CONFIRMED, SHIPPED, DELIVERED }
    
    StateMachineTool("orderProcessor", "Process orders", OrderState::class.java)
        .withInitialState(OrderState.DRAFT)
        .inState(OrderState.DRAFT)
            .withTool(addItemTool)
            .withTool(confirmTool).transitionsTo(OrderState.CONFIRMED)
        .inState(OrderState.CONFIRMED)
            .withTool(shipTool).transitionsTo(OrderState.SHIPPED)
        .inState(OrderState.SHIPPED)
            .withTool(deliverTool).transitionsTo(OrderState.DELIVERED)
        .inState(OrderState.DELIVERED)
            .withTool(reviewTool)