Add dispatch tool

From suxrobGM/logistics-app · View interactive version

Add dispatch tool is an AI agent skill from the GitHub repository suxrobGM/logistics-app. Add a new tool to the AI agents (dispatch, copilot, MCP). Use when the user wants an agent to gain a capability (e.g. "add a tool that returns load board listings older than 24h"). Covers the one file to add, its folder, and the metadata that silently decides who can call it.

How to use this skill

Skill file

Add an agent tool

A tool is one class. AgentToolCatalog discovers it at startup and feeds DI and every surface, so Registrar.cs and AgentToolRegistry.cs never change. Rules behind this recipe: .claude/rules/backend/ai-agent.md.

1. Write the tool

src/Infrastructure/Logistics.Infrastructure.AI/Tools/{Domain}/{Name}Tool.cs. {Domain} is the module it calls: Dispatch, Financial, Operations, Compliance, LoadBoard, Intermodal, Negotiation.

namespace Logistics.Infrastructure.AI.Tools.Operations;

internal sealed class GetSomethingTool(IMediator mediator)
    : AgentTool<GetSomethingTool.Input>, IAgentToolMetadata
{
    internal sealed record Input
    {
        [Description("GUID of the load")]
        [AgentEntityId(AgentEntityKind.Load)]
        public required Guid LoadId { get; init; }

        [Description("Page number when a previous call returned truncated: true")]
        public int? Page { get; init; }
    }

    public static AgentToolDefinition Definition => new(
        "get_something",
        "Returns X for Y. One or two sentences: inputs, output, when to use it over alternatives.")
    {
        RequiredPermission = Permission.Load.View,   // always
        RequiredFeature = TenantFeature.Loads,       // when gated
        DecisionType = AgentDecisionType.AssignLoad, // writes only
        Surfaces = AgentSurfaces.All                 // omit for copilot only
    };

    protected override async Task<string> ExecuteAsync(Input input, CancellationToken ct)
    {
        var result = await mediator.Send(new GetSomethingQuery { LoadId = input.LoadId }, ct);
        return result.IsSuccess ? ToolResult.Ok(result.Value) : ToolResult.Error(result.Error ?? "Unknown error");
    }
}

2. Get the metadata right

None of these fail loudly when wrong.

3. Test

test/Logistics.Infrastructure.AI.Tests/Tools/{Domain}/{Name}ToolTests.cs. Call ExecuteAsync(JsonNode, ct) so binding is covered. Test a missing required input (result contains "error") and the happy path. Naming is already covered by catalogue tests.

dotnet build, then dotnet test --filter-class "*{Name}ToolTests".

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.