The Copilot Agent SDK enables the development of custom AI agents for GitHub Copilot. This allows you to extend Copilot with your business logic.
What is the Copilot Agent SDK?
The SDK is a framework for creating:
- Custom Agents – Specialized AI assistants
- Tool Integrations – Connect external systems
- Workflow Automation – Automate complex processes
- Domain Experts – Incorporate industry-specific knowledge
Architecture Overview
Components
[GitHub Copilot] ←→ [Agent Runtime]
↓
[Your Agent]
↓
[Tools] [Memory] [Context]Agent Lifecycle
- 1Initialization – Agent is loaded
- 2Context Building – Relevant context is provided
- 3Reasoning – Agent processes the request
- 4Tool Execution – Agent utilizes tools
- 5Response – Result is returned
Getting Started
Installation
npm install @github/copilot-agent-sdkCreate a Basic Agent
import { Agent, AgentContext } from '@github/copilot-agent-sdk';
export class MyCustomAgent extends Agent {
name = 'my-custom-agent';
description = 'An agent for specific tasks';
async execute(context: AgentContext): Promise<string> {
const { query, files, history } = context;
// Your logic here
const result = await this.processQuery(query);
return result;
}
}Register the Agent
import { registerAgent } from '@github/copilot-agent-sdk';
import { MyCustomAgent } from './my-agent';
registerAgent(new MyCustomAgent());Agent Configuration
Manifest
name: my-custom-agent
version: 1.0.0
description: Description of the agent
capabilities:
- code-generation
- file-operations
- external-api
triggers:
- pattern: "@myagent"
description: Activates the custom agentPermissions
permissions:
files:
read: true
write: true
network:
allowed_hosts:
- api.cnext.ch
secrets:
- MY_API_KEYContext and Memory
Accessing Context
async execute(context: AgentContext) {
// Current file
const currentFile = context.activeFile;
// Workspace files
const files = await context.workspace.getFiles('**/*.ts');
// Conversation history
const previousMessages = context.history;
// User preferences
const preferences = context.user.preferences;
}Long-Term Memory
// Save
await context.memory.set('lastAnalysis', analysisResult);
// Retrieve
const cached = await context.memory.get('lastAnalysis');
// With TTL
await context.memory.set('session', data, { ttl: 3600 });Defining Tools
Tool Structure
import { Tool, ToolResult } from '@github/copilot-agent-sdk';
const searchTool: Tool = {
name: 'search-docs',
description: 'Searches the documentation',
parameters: {
query: { type: 'string', required: true },
limit: { type: 'number', default: 10 }
},
execute: async (params): Promise<ToolResult> => {
const results = await searchDocumentation(params.query);
return { success: true, data: results };
}
};Registering Tools
class MyAgent extends Agent {
tools = [searchTool, analyzeTool, generateTool];
}Testing
Unit Tests
import { TestContext } from '@github/copilot-agent-sdk/testing';
describe('MyCustomAgent', () => {
it('should process query correctly', async () => {
const agent = new MyCustomAgent();
const context = TestContext.create({
query: 'Analyze the code',
files: ['src/main.ts']
});
const result = await agent.execute(context);
expect(result).toContain('Analysis');
});
});Integration Tests
npx copilot-agent test --interactiveDeployment
Local Development
npx copilot-agent devPublishing
npx copilot-agent publishBest Practices
Clear Responsibilities
- One agent = One task
- Focused functionality
- Good descriptions
Error Handling
try {
const result = await externalApi.call();
return formatSuccess(result);
} catch (error) {
logger.error('API call failed', error);
return formatError('Please try again later');
}Performance
- Use caching
- Parallel tool execution
- Streaming for long responses
CNEXT Support
We assist with:
- 1Agent Design – Define use cases
- 2Development – Build custom agents
- 3Integration – Connect enterprise systems
- 4Deployment – Secure rollout
Conclusion
The Copilot Agent SDK turns Copilot into your platform. Develop agents that understand your business.

