This directory defines the Tools used by AiAgent2 and other AI agents to execute code, read page state, or apply mutations to the inspected page.
The architecture relies on three primary concepts to guarantee 100% compile-time type safety for tools:
name, description, parameters). This allows the agent and DevTools UI to generically store, register, and describe functions to the AIDA client without needing to know their specific types at runtime.Tool<Args, ReturnType, ContextType>) binding the execution handler to specific capability requirements. This enforces compile-time safety, ensuring that a tool handler is only invoked by an agent that fulfills all the required capabilities.Instead of passing a monolithic “grab-bag” context object to all tool handlers, DevTools AI tools declare exactly the capabilities they require. Available capability interfaces defined in Tool.ts include:
BaseToolCapability: Base interface providing access to the top-level conversation context step.PageExecutionCapability: For tools executing JavaScript code on the inspected page.StyleMutationCapability: For tools managing and applying style mutations via a ChangeManager.TargetCapability: For tools requiring access to the page's current SDK Target.OriginLockCapability: For tools enforcing cross-origin security via origin locks. Tools that fetch resources or state from the inspected page (such as styling or source code) must use this capability to verify that the target resource matches the conversation's established origin. This prevents the LLM from executing tools against out-of-origin elements or documents.The Agent (e.g., AiAgent2) builds the complete dependency union (AllToolsContext) and fulfills all capabilities. When the handler is invoked, TypeScript validates that the provided context matches the intersection of capabilities requested by that tool.
To author a new tool:
ToolArgs to represent the JSON parameter schema expected by the LLM.ContextType.Tool interface: Pass the args interface, return type, and intersected ContextType to the generic parameters of Tool.ToolRegistry.ts: Add the instantiated tool class to the static TOOLS registry.See concrete, production examples of capability-based tools in this directory:
PageExecutionCapability and StyleMutationCapability.TargetCapability and OriginLockCapability.To retrieve a tool from the registry with 100% type safety, call ToolRegistry.get() with the literal ToolName key:
const getStylesTool = ToolRegistry.get(ToolName.GET_STYLES); // Returns GetStylesTool class type