Make it work

This commit is contained in:
Sean Goedecke
2025-07-15 23:31:48 +00:00
parent 0b82ac474e
commit 886d4717d7
3 changed files with 164 additions and 13 deletions
Generated Vendored
+74 -6
View File
@@ -48938,6 +48938,7 @@ async function run() {
const mcpServerUrl = 'https://api.githubcopilot.com/mcp/';
const enableMcp = coreExports.getBooleanInput('enable-mcp') || false;
let azureTools = [];
let mcp = null;
// Connect to MCP server if enabled
if (enableMcp || true) {
coreExports.info('Connecting to GitHub MCP server...' + token);
@@ -48948,7 +48949,7 @@ async function run() {
}
}
});
const mcp = new Client({
mcp = new Client({
name: 'ai-inference-action',
version: '1.0.0',
transport
@@ -49003,16 +49004,83 @@ async function run() {
'): ' +
response.body);
}
const modelResponse = response.body.choices[0].message.content;
let modelResponse = response.body.choices[0].message.content;
coreExports.info(`Model response: ${response || 'No response content'}`);
// Handle tool calls if present
const toolCalls = response.body.choices[0].message.tool_calls;
if (toolCalls && toolCalls.length > 0) {
if (toolCalls && toolCalls.length > 0 && mcp) {
coreExports.info(`Model requested ${toolCalls.length} tool calls`);
// Note: For now, we'll just log the tool calls
// In a full implementation, you'd execute them via MCP and continue the conversation
// Execute tool calls via MCP and continue the conversation
const toolResults = [];
for (const toolCall of toolCalls) {
coreExports.info(`Tool call: ${toolCall.function.name} with args: ${toolCall.function.arguments}`);
coreExports.info(`Executing tool: ${toolCall.function.name} with args: ${toolCall.function.arguments}`);
try {
// Parse the arguments from JSON string
const args = JSON.parse(toolCall.function.arguments);
// Call the tool via MCP
const result = await mcp.callTool({
name: toolCall.function.name,
arguments: args
});
coreExports.info(`Tool ${toolCall.function.name} executed successfully`);
// Store the result for the follow-up conversation
toolResults.push({
tool_call_id: toolCall.id,
role: 'tool',
name: toolCall.function.name,
content: JSON.stringify(result.content)
});
}
catch (toolError) {
coreExports.warning(`Failed to execute tool ${toolCall.function.name}: ${toolError}`);
// Add error result to continue conversation
toolResults.push({
tool_call_id: toolCall.id,
role: 'tool',
name: toolCall.function.name,
content: `Error: ${toolError}`
});
}
}
// If we have tool results, continue the conversation
if (toolResults.length > 0) {
coreExports.info('Continuing conversation with tool results...');
// Build the follow-up request with the original conversation + tool results
const followUpMessages = [
{
role: 'system',
content: systemPrompt
},
{ role: 'user', content: prompt },
{
role: 'assistant',
content: modelResponse,
tool_calls: toolCalls
},
...toolResults
];
const followUpRequest = {
messages: followUpMessages,
max_tokens: maxTokens,
model: modelName
};
// Add tools again for potential follow-up tool calls
if (azureTools.length > 0) {
followUpRequest.tools = azureTools;
}
const followUpResponse = await client.path('/chat/completions').post({
body: followUpRequest
});
if (isUnexpected(followUpResponse)) {
coreExports.warning('Failed to get follow-up response after tool execution: ' +
followUpResponse.status + ': ' + followUpResponse.body);
}
else {
const finalResponse = followUpResponse.body.choices[0].message.content;
coreExports.info(`Final response after tool execution: ${finalResponse}`);
// Update the model response to the final one
modelResponse = finalResponse || modelResponse;
}
}
}
// Set outputs for other workflow steps to use
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+89 -6
View File
@@ -70,6 +70,7 @@ export async function run(): Promise<void> {
const enableMcp = core.getBooleanInput('enable-mcp') || false
let azureTools: any[] = []
let mcp: Client | null = null
// Connect to MCP server if enabled
if (enableMcp || true) {
@@ -86,7 +87,7 @@ export async function run(): Promise<void> {
}
)
const mcp = new Client({
mcp = new Client({
name: 'ai-inference-action',
version: '1.0.0',
transport
@@ -153,21 +154,103 @@ export async function run(): Promise<void> {
)
}
const modelResponse: string | null =
let modelResponse: string | null =
response.body.choices[0].message.content
core.info(`Model response: ${response || 'No response content'}`)
// Handle tool calls if present
const toolCalls = response.body.choices[0].message.tool_calls
if (toolCalls && toolCalls.length > 0) {
if (toolCalls && toolCalls.length > 0 && mcp) {
core.info(`Model requested ${toolCalls.length} tool calls`)
// Note: For now, we'll just log the tool calls
// In a full implementation, you'd execute them via MCP and continue the conversation
// Execute tool calls via MCP and continue the conversation
const toolResults: any[] = []
for (const toolCall of toolCalls) {
core.info(
`Tool call: ${toolCall.function.name} with args: ${toolCall.function.arguments}`
`Executing tool: ${toolCall.function.name} with args: ${toolCall.function.arguments}`
)
try {
// Parse the arguments from JSON string
const args = JSON.parse(toolCall.function.arguments)
// Call the tool via MCP
const result = await mcp.callTool({
name: toolCall.function.name,
arguments: args
})
core.info(`Tool ${toolCall.function.name} executed successfully`)
// Store the result for the follow-up conversation
toolResults.push({
tool_call_id: toolCall.id,
role: 'tool',
name: toolCall.function.name,
content: JSON.stringify(result.content)
})
} catch (toolError) {
core.warning(`Failed to execute tool ${toolCall.function.name}: ${toolError}`)
// Add error result to continue conversation
toolResults.push({
tool_call_id: toolCall.id,
role: 'tool',
name: toolCall.function.name,
content: `Error: ${toolError}`
})
}
}
// If we have tool results, continue the conversation
if (toolResults.length > 0) {
core.info('Continuing conversation with tool results...')
// Build the follow-up request with the original conversation + tool results
const followUpMessages = [
{
role: 'system',
content: systemPrompt
},
{ role: 'user', content: prompt },
{
role: 'assistant',
content: modelResponse,
tool_calls: toolCalls
},
...toolResults
]
const followUpRequest: any = {
messages: followUpMessages,
max_tokens: maxTokens,
model: modelName
}
// Add tools again for potential follow-up tool calls
if (azureTools.length > 0) {
followUpRequest.tools = azureTools
}
const followUpResponse = await client.path('/chat/completions').post({
body: followUpRequest
})
if (isUnexpected(followUpResponse)) {
core.warning(
'Failed to get follow-up response after tool execution: ' +
followUpResponse.status + ': ' + followUpResponse.body
)
} else {
const finalResponse = followUpResponse.body.choices[0].message.content
core.info(`Final response after tool execution: ${finalResponse}`)
// Update the model response to the final one
modelResponse = finalResponse || modelResponse
}
}
}