Crestapps core a2a

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core a2a is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for Agent-to-Agent (A2A) protocol support in CrestApps.Core on the A2A 1.0 SDK. Covers AddA2AClient and AddCoreAIA2AClient with Entity Framework Core or YesSql connection stores, A2AConnection and A2AConnectionMetadata authentication, AIProfileA2AMetadata, the agent card cache and A2AToolRegis

How to use this skill

Skill file

CrestApps.Core A2A

Use A2A when the remote system is an agent that reasons on its own (its own model, tools and context). Use MCP (crestapps-core-mcp) when the remote system exposes tools or resources. CrestApps.Core.AI.A2A ships the client; hosting is application code built on the A2A and A2A.AspNetCore 1.0 SDK packages, using A2AHostOptions from the framework.

Client

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddA2AClient(a2a => a2a
            .AddEntityCoreStores()))   // or .AddYesSqlStores(); registers ICatalog<A2AConnection>
    .AddEntityCoreSqliteDataStore("Data Source=app.db"));

AddCoreAIA2AClient() registers a resilient named HttpClient, IMemoryCache, A2AAICompletionContextBuilderHandler, A2AToolRegistryProvider, IA2AAgentCardCacheService (15-minute cache), IA2AConnectionAuthService, and the system tools listAvailableAgents, findAgentForTask and findToolsForTask.

Connections

using CrestApps.Core;
using CrestApps.Core.AI.A2A;
using CrestApps.Core.AI.A2A.Models;
using CrestApps.Core.AI.Models;

var protector = dataProtectionProvider.CreateProtector(A2AConstants.DataProtectionPurpose); // "A2AClientConnection"

var connection = new A2AConnection
{
    DisplayText = "Legal Review Agent",
    Endpoint = "https://agents.example.com/",
};

connection.Put(new A2AConnectionMetadata
{
    AuthenticationType = ClientAuthenticationType.ApiKey,
    ApiKeyHeaderName = "Authorization",
    ApiKeyPrefix = "Bearer",
    ApiKey = protector.Protect(apiKey),
});

await connectionCatalog.CreateAsync(connection);

profile.Put(new AIProfileA2AMetadata { ConnectionIds = [connection.ItemId] });

Host

There is no packaged host extension. The MVC and Blazor sample hosts implement the pattern below internally.

using A2A;
using A2A.AspNetCore;
using CrestApps.Core.AI.A2A.Models;

builder.Services.Configure<A2AHostOptions>(builder.Configuration.GetSection("A2AHostOptions"));
builder.Services.AddSingleton<IAgentHandler, ProfileAgentHandler>();
builder.Services.AddSingleton<ChannelEventNotifier>();
builder.Services.AddSingleton<ITaskStore, InMemoryTaskStore>();
builder.Services.AddSingleton<IA2ARequestHandler>(sp => new A2AServer(
    sp.GetRequiredService<IAgentHandler>(),
    sp.GetRequiredService<ITaskStore>(),
    sp.GetRequiredService<ChannelEventNotifier>(),
    sp.GetRequiredService<ILogger<A2AServer>>()));

var app = builder.Build();

app.MapGet("/.well-known/agent-card.json", WriteAgentCardsAsync);
app.MapA2A(app.Services.GetRequiredService<IA2ARequestHandler>(), "a2a")
    .RequireAuthorization("A2AHostPolicy");
public sealed class ProfileAgentHandler : IAgentHandler
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public ProfileAgentHandler(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }

    public async Task ExecuteAsync(RequestContext context, AgentEventQueue eventQueue, CancellationToken cancellationToken)
    {
        var updater = new TaskUpdater(eventQueue, context.TaskId, context.ContextId);
        var services = _httpContextAccessor.HttpContext.RequestServices;

        if (!context.IsContinuation)
        {
            await updater.SubmitAsync(cancellationToken: cancellationToken);
        }

        await updater.StartWorkAsync(cancellationToken: cancellationToken);

        // Resolve the agent profile (from ?agent= or the message metadata "agentName"),
        // build its completion context, stream IAICompletionService output with updater.AddArtifactAsync(...),
        // then finish with updater.CompleteAsync(message) or updater.FailAsync(message).
    }
}

Agent Cards (A2A 1.0)

A 1.0 card no longer has a top-level url. The endpoint is declared in supportedInterfaces:

var card = new AgentCard
{
    Name = profile.DisplayText ?? profile.Name,
    Description = profile.Description,
    Version = "1.0",
    SupportedInterfaces =
    [
        new AgentInterface
        {
            Url = $"{baseUrl}/a2a?agent={Uri.EscapeDataString(profile.Name)}",
            ProtocolBinding = "JSONRPC",
            ProtocolVersion = "1.0",
        },
    ],
    DefaultInputModes = ["text/plain"],
    DefaultOutputModes = ["text/plain"],
    Capabilities = new AgentCapabilities { Streaming = true },
    Skills = [new AgentSkill { Id = profile.Name, Name = profile.DisplayText ?? profile.Name, Description = profile.Description, Tags = ["agent"] }],
};
{
  "name": "Legal Review Agent",
  "description": "Reviews contracts.",
  "version": "1.0",
  "supportedInterfaces": [
    { "url": "https://agents.example.com/a2a?agent=legal-review", "protocolBinding": "JSONRPC", "protocolVersion": "1.0" }
  ],
  "capabilities": { "streaming": true },
  "skills": [ { "id": "legal-review", "name": "Legal Review Agent", "tags": [ "agent" ] } ]
}

Advertise authentication with SecuritySchemes and SecurityRequirements (an ApiKeySecurityScheme on the Authorization header, or an OpenIdConnectSecurityScheme pointing at /.well-known/openid-configuration).

A2AHostOptions

| Property | Default | Meaning |

|---|---|---|

| AuthenticationType | OpenId | OpenId, ApiKey or None (development only) |

| ApiKey | | shared secret for ApiKey mode, sent as Authorization: Bearer {key} |

| RequireAccessPermission | true | for OpenId, also require the host's A2A access permission |

| ExposeAgentsAsSkill | false | false publishes one card per agent (a JSON array); true publishes one card whose skills are the agents |

The options are settings only; the host enforces them in its authentication handler and authorization policy.

Cards are built from IAIProfileManager.GetAsync(AIProfileType.Agent), which includes code-defined system agents such as tabular-data-agent, presentation-agent, word-agent and pdf-agent. They are hidden from UI pickers but discoverable by remote clients. Filter the list if they should stay private.

Upgrading from 1.x

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.