{"record":{"id":"ae749959805ffe71","repo":"microsoft/aspire","slug":"tool-tool-name-belongs-to-project-tool-project-name-but","errorCode":null,"errorMessage":"Tool '{tool.Name}' belongs to project '{tool.Project.Name}' but agent '{Name}' belongs to project '{Project.Name}'. All tools must belong to the same project as the agent.","messagePattern":"Tool '(.+?)' belongs to project '(.+?)' but agent '(.+?)' belongs to project '(.+?)'\\. All tools must belong to the same project as the agent\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Foundry/PromptAgent/AzurePromptAgentResource.cs","lineNumber":154,"sourceCode":"    public StaticValueProvider<string> Version { get; } = new();\n\n    /// <summary>\n    /// Gets the list of tool resources attached to this agent.\n    /// </summary>\n    [AspireExportIgnore(Reason = \"IFoundryTool is a .NET extensibility point and is not ATS-compatible.\")]\n    public IReadOnlyList<IFoundryTool> Tools => _tools;\n\n    /// <summary>\n    /// Adds a tool resource to this prompt agent.\n    /// </summary>\n    /// <param name=\"tool\">The tool resource to add.</param>\n    internal void AddTool(FoundryToolResource tool)\n    {\n        ArgumentNullException.ThrowIfNull(tool);\n\n        if (tool.Project != Project)\n        {\n            throw new InvalidOperationException(\n                $\"Tool '{tool.Name}' belongs to project '{tool.Project.Name}' but agent '{Name}' \" +\n                $\"belongs to project '{Project.Name}'. All tools must belong to the same project as the agent.\");\n        }\n\n        _tools.Add(tool);\n    }\n\n    /// <inheritdoc/>\n    public ReferenceExpression ConnectionStringExpression =>\n        ReferenceExpression.Create($\"{Project.Endpoint}/agents/{Name}\");\n\n    IEnumerable<KeyValuePair<string, ReferenceExpression>> IResourceWithConnectionString.GetConnectionProperties()\n    {\n        yield return new(\"AgentName\", ReferenceExpression.Create($\"{Name}\"));\n        yield return new(\"ProjectEndpoint\", ReferenceExpression.Create($\"{Project.Endpoint}\"));\n        yield return new(\"ConnectionString\", ConnectionStringExpression);\n    }\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Foundry/PromptAgent/AzurePromptAgentResource.cs#L136-L172","documentation":"A Foundry prompt agent can only use tools whose backing Foundry project matches the agent's own project. AddTool validates this at the resource-model level and throws when a tool is registered against a different Foundry project instance than the one the agent belongs to.","triggerScenarios":"Calling WithTool (which routes to AddTool) on an agent built from project A, passing a tool (e.g. an Azure AI Search or Bing tool) whose Project is project B.","commonSituations":"Apps with multiple Foundry projects where tools and agents are wired across projects; reusing a tool definition from another AppHost section or another project builder.","solutions":["Create the tool from the same Foundry project the agent uses, e.g. project.AddAISearchTool(...) instead of anotherProject.AddAISearchTool(...).","Check that the resource passed to WithTool was not built against a second AddAzureFoundry project.","Consolidate to a single Foundry project resource if both agent and tool should live together."],"exampleFix":"// before\nvar tool = otherProject.AddBingGroundingTool(\"bing\");\nagent.WithTool(tool);\n// after\nvar tool = project.AddBingGroundingTool(\"bing\");\nagent.WithTool(tool);","handlingStrategy":"validation","validationCode":"if (!ReferenceEquals(tool.Project, agent.Project)) throw new InvalidOperationException($\"Tool '{tool.Name}' must be added from the agent's Foundry project '{agent.Project.Name}'.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create tools from the same project builder instance used to create agents.","Avoid holding Foundry project resources in globals that can mix projects.","In multi-project apps, name project resources clearly and keep agent+tool wiring adjacent."],"tags":["azure","foundry","agent","tool","project-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}