unity-mcp icon indicating copy to clipboard operation
unity-mcp copied to clipboard

State-Aware Dependency System Help the tool

Open whatevertogo opened this issue 10 months ago • 9 comments

Allow AI to search for the content it needs through multi-level tools layer by layer, rather than giving it everything at

whatevertogo avatar Jan 18 '26 03:01 whatevertogo

I am actually working on this at the same time! Sounds like something is needed before Anthropic throws another cool trick at us. I don't think our tool layer is really comprehensive at this point in time, though. We can review code changes, but make sure to have a comparison on tokens/performances so we can better evaluate.

Scriptwonder avatar Jan 19 '26 04:01 Scriptwonder

I am actually working on this at the same time! Sounds like something is needed before Anthropic throws another cool trick at us. I don't think our tool layer is really comprehensive at this point in time, though. We can review code changes, but make sure to have a comparison on tokens/performances so we can better evaluate.

Actually, I want to consider solving the problem from the mcp architecture (FaseMCP) layer, rather than through something like Custom_Tool call. However, I'm concerned that this might require a lot of time to implement.

whatevertogo avatar Jan 19 '26 04:01 whatevertogo

Then I guess it is outside the current repo usage (or its just on the python side)? Also, does Issue#560 kind of serve as a similar way to deal with optimization?

Scriptwonder avatar Jan 19 '26 04:01 Scriptwonder

just the python side i think

whatevertogo avatar Jan 19 '26 05:01 whatevertogo

Then I guess it is outside the current repo usage (or its just on the python side)? Also, does Issue#560 kind of serve as a similar way to deal with optimization?

Implement a state-aware dependency system for tool management. The C# side should expose an HTTP API (via EditorStateProvider) to report real-time editor states (e.g., compiling, playing, selection). The Python MCP Server will then use this state to dynamically filter the tool list via a prerequisite_check decorator, ensuring AI agents only see actions that are currently valid.

Control tool visibility based on real-time environmental states (e.g., whether objects exist ) rather than on historical steps. Tools are coexistent rather than mutually exclusive, allowing free jumping between different levels.

That's my idea,so what do you think

whatevertogo avatar Jan 19 '26 05:01 whatevertogo

Just saw this. I still don't see the exact usage of this, as far as this seems to be a way to build the LLM's understanding without relying on previous history (which isn't realistic, considering this is LLM); As towards an HTTP api, how many tokens will it burn just for the MCP server to retrieve the editor state at a certain frame? And for the end goal, can you let me know which tools NEED to be filtered at certain times for editor states?

Scriptwonder avatar Jan 21 '26 18:01 Scriptwonder

I think there may be a small mismatch in expectations here.

Regarding Performance & Token Cost: Editor state prerequisite checks are evaluated directly in the Python/C# layer, not by the LLM. Tokens are only spent after a tool is deemed valid and the AI chooses to call it, which makes this filtering mechanism a net token saver.

The Hook system is not an update or polling mechanism. It’s purely event-driven. Nothing is pushed every frame, and no editor state is streamed continuously. A hook only fires when something meaningful happens (selection change, asset import, play mode switch, etc.). Because of that, the token cost is not proportional to time or frames. If nothing happens, nothing is sent. When a hook does fire, the payload is intentionally minimal and structured, closer to a diff or fact report than a snapshot of the world.

And the most important thing is that we use it just for recording or changing states,ai need to use tool to konw the states. Editor state can reflect the tool list ai can used.(main point)

Concrete Examples of State-Aware Filtering: Here are scenarios where this approach prevents failures that a "history-only" LLM would struggle with:

Compilation Guard: If EditorApplication.isCompiling is true, the ModifyScript and PlayMode tools are automatically hidden. This prevents the AI from making concurrent changes that would corrupt the assembly or throw "AssetDatabase is busy" errors.

Contextual Tooling: The AdjustTransform tool only appears in the LLM's manifest if Selection.activeGameObject is not null. If nothing is selected, the tool doesn't exist in the prompt, saving tokens and narrowing the AI's focus.

Play-Mode Safety: Certain destructive tools (like DeleteAsset) can be flagged to require a isPaused state or be disabled entirely during Play Mode to ensure editor stability.

Technical Feasibility: These checks are lightweight. The C# EditorStateProvider simply exposes existing flags like EditorApplication.isCompiling and Selection.activeGameObject != null.

By checking these before serializing the tool definitions for the LLM, we ensure that the model's action space is always synchronized with the Editor's functional state. This moves the complexity of "state validation" from the expensive, probabilistic LLM layer to the cheap, deterministic C# layer.

whatevertogo avatar Jan 22 '26 18:01 whatevertogo

The State-Aware Dependency System is not about enriching context or replacing internal reasoning. Its primary role is to enforce editor-level constraints outside the model, ensuring that only actions which are valid in the current Unity state are exposed to the AI.

By resolving state checks in the C#/Python layer before tool serialization, we shift validation from the probabilistic LLM layer to a deterministic, low-cost runtime layer. This reduces token waste and prevents invalid actions.

Future-Proofing for Multi-Agent Workflows: While this doesn't implement coordination by itself, it establishes the shared, authoritative view of editor state that any safe multi-agent setup requires. It ensures all agents operate against the same action boundaries, preventing race conditions and instability during sensitive phases like Domain Reloads.

The Bottom Line: It narrows the model’s action space to what is physically possible in the editor, providing a necessary safety foundation for today’s reliability and tomorrow’s advanced collaboration.

I believe we can have Multi-Agent agent workflow in unity-mcp. Won't you want it?.I create actiontrace system also for it.

whatevertogo avatar Jan 22 '26 18:01 whatevertogo

Closing since it's getting stale and didn't seem like it was going forward

dsarno avatar Feb 17 '26 14:02 dsarno