
Agent Modes
FreeManage agent context with tailored modes for better outcomes.
Free · Opens the source repo
What Agent Modes does
The Agent Modes skill provides a structured approach to creating and managing modes for the PostHog AI agent. Modes are essential for controlling the context in which the agent operates, allowing developers to specify which tools, prompts, and behaviors are applied based on the current task or product area. By defining modes, users can enhance the agent's effectiveness for specific use cases, ensuring that it operates with the right context and tools at its disposal.
To implement a new mode, users can follow a clear set of guidelines that include determining a suitable mode name, creating the necessary schema, and updating the agent's toolkit with relevant tools. Each mode should encapsulate specific functionalities tailored to particular products or tasks, making it easier for the agent to deliver precise results. The skill also emphasizes the importance of context management, enabling the agent to switch modes dynamically while preserving the current context, which is crucial for maintaining continuity in user interactions.
This skill is particularly useful for developers working with the PostHog platform who need to customize the AI agent’s behavior for various analytics tasks. By leveraging the Agent Modes skill, developers can ensure that their AI agents are equipped with the appropriate tools and instructions for the specific scenarios they encounter, ultimately leading to improved performance and user satisfaction. The structured approach provided by this skill helps streamline the development process, making it easier to implement and maintain agent modes over time.
When to use it
Use this skill when you need to create or update modes for the PostHog AI agent to enhance its functionality for specific tasks.
When not to use it
Avoid this skill if you do not require custom agent behavior or if you are working with a static set of tools and prompts.
What you can build with it
Customizing Analytics Tools
Developers can create a mode specifically for product analytics, ensuring that the AI agent uses the right tools and prompts for data analysis.
Dynamic Context Management
By implementing modes, teams can switch the agent's context based on user needs, enhancing the relevance of the agent's responses.
Feature Flagging New Modes
When introducing new modes, developers can use feature flags to control access, ensuring that only intended users can utilize the new functionalities.
How to install Agent Modes
View source1. Install with the skills CLI
npx skills add posthog/posthog/implementing-agent-modes --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by posthogAgent modes
Use the steps below to plan or implement a new mode. A mode is a way to manage the context of the agent and inject tools, prompts, and mode-related behavior relevant to a product, use case, JTBD, etc. The agent has the switch_mode tool that allows it to switch itself to another mode, which might change tools, prompt, and executables, preserving the current context. Some previously created tools are contextual, meaning they're injected on particular pages of the frontend. The modes change the approach and always have tools in the mode context.
Determine mode name
Explore the ee/hogai/core/agent_modes/presets directory and check if there are already modes that match the user's intent. If you want to create a new mode, you should scope it by a PostHog product (Product analytics), product area (SQL), or agent (Instrumentation agent).
(optionally) Create a new mode in schema
Add a new AgentMode to frontend/src/queries/schema/schema-assistant-messages.ts and regenerate the schema using:
hogli build:schema
Alternatively, you may use this command:
pnpm run schema:build
Create or update mode's scaffolding
A mode should typically contain at least two things:
- An AgentToolkit exposing tools that are specific to the mode and trajectory examples for the todo tool.
- An AgentModeDefinition containing the AgentMode, mode description that is always injected into the context window of the agent, and classes for toolkit and executables.
Note: you should only create new executables if the user needs to modify the prompt, behavior of that mode, or the execution loop itself.
Adding tools to the mode
Relevant tools might be located in ee/hogai/tools or products/<product_name>/backend/max_tools. There is a set of tools that is always injected into the context, like the read_data tool, but all other tools should be specific to the mode.
Before adding a tool to the toolkit, determine if those tools have tool dependencies. If there are dependencies (like an experiment depends on feature flag creation), loop back to the user to determine whether they want to merge modes into a single one. If they don't want to do that, make sure that you later add a trajectory example clearly explaining mode switching and tool selection.
You should also verify that the tools are backend-first. If tools apply frontend changes without passing proper context back to the conversation, you should propose a way to make them backend-first so the agent has the right context.
Review the default toolkit
If the new mode contains new Django models, you should review whether the read_data, search, and list_data tools have the functionality to retrieve the models. If they don't support these models, you should use or implement one of the context providers available in ee/hogai/context/....
Write JTBD-like trajectory examples
Update the AgentToolkit to include trajectory examples. These should be JTBD-style examples showing how the agent should achieve typical tasks with the available tools. Check the Product analytics preset for reference.
Implement frontend
Update max-constants.tsx to include new tools and add the mode to the mode selector. You might also need to create new UI elements for displaying data from the tools.
Example
Say you've updated the Error tracking tool to list issues. It used to be a frontend tool that only updated filters, but now it outputs error tracking issues. While the agent has the context it needs, the user also needs to see the issues in a human-readable way. In this case, you should design and implement a new component to display the tool's output.
Add feature flag
All new modes must be feature-flagged. Example:
@property
def mode_registry(self) -> dict[AgentMode, AgentModeDefinition]:
registry = dict(DEFAULT_CHAT_AGENT_MODE_REGISTRY)
if has_error_tracking_mode_feature_flag(self._team, self._user):
registry[AgentMode.ERROR_TRACKING] = error_tracking_agent
return registry
If you have created new tools, make sure you feature flag them correctly:
- Old tools that are being migrated should not be available if the feature flag is active.
- New tools should only be available if the feature flag is active.
Implement and update tests
You should test new tools, presets, executables, and optionally implement evals.
Frequently asked questions about Agent Modes
Similar skills
WinMD API Search
Easily find and explore Windows desktop APIs.
WebMCPify
Transform any web app into an agent-ready platform.
Phoenix Tracing
Instrument LLM applications with OpenInference tracing.
Foundry Hosted Agent CopilotKit
Guidance for developing agentic web apps on Azure.
Power Automate Foundation
Connect AI agents to Power Automate seamlessly.
Power Automate Flow Builder
Efficiently build and deploy Power Automate flows programmatically.
