Skip to content

Fix OpenAI API errors, session logging warnings, and infinite loops in AgentAlpha#66

Merged
johnkord merged 3 commits intomainfrom
copilot/fix-65
Jun 25, 2025
Merged

Fix OpenAI API errors, session logging warnings, and infinite loops in AgentAlpha#66
johnkord merged 3 commits intomainfrom
copilot/fix-65

Conversation

Copy link
Copy Markdown

Copilot AI commented Jun 25, 2025

This PR fixes three critical bugs identified in the AgentAlpha GitHub PR review workflow that were causing execution failures:

🔧 Issues Fixed

1. OpenAI API "Unknown parameter: 'tool_choice.function'" Error

Problem: PlanningService was using an outdated OpenAI API format for the tool_choice parameter, causing requests to fail with:

System.InvalidOperationException: OpenAI API error: BadRequest – {
  "error": {
    "message": "Unknown parameter: 'tool_choice.function'.",
    "type": "invalid_request_error",
    "param": "tool_choice.function",
    "code": "unknown_parameter"
  }
}

Solution: Updated the tool_choice format to use the correct API specification:

// Before (causing errors)
ToolChoice = new { type = "function", function = new { name = "create_execution_plan" } }

// After (working correctly)
ToolChoice = "required"

2. Session Activity Logger "Cannot log activity - no current session set" Warnings

Problem: When using the simple ExecuteAsync(string task) method, no session was created, causing repeated warnings:

warn: AgentAlpha.Services.SessionActivityLogger[0]
      Cannot log activity - no current session set

Solution: Added automatic default session creation when no session is provided, ensuring activity logging works in all execution scenarios.

3. Infinite Loop When Tools Return Errors

Problem: When GitHub API returned 404 errors (or similar), the agent would get stuck repeating the same response indefinitely:

AI: It seems there was an issue accessing the pull request details...
AI: It seems there was an issue accessing the pull request details...
AI: It seems there was an issue accessing the pull request details...

Solution: Implemented comprehensive repetitive response detection:

  • Tracks the last 5 assistant responses
  • Detects when >80% word similarity indicates repetition
  • Breaks conversation loops after 3 iterations if stuck
  • Provides guidance messages to help the agent move forward
  • Logs warnings when repetitive behavior is detected

🧪 Testing

  • ✅ All existing tests pass (207 tests, no regressions)
  • ✅ Build succeeds without warnings
  • ✅ Manual testing confirms all three issues are resolved

📁 Files Modified

  • src/Agent/AgentAlpha/Services/PlanningService.cs - Fixed OpenAI API compatibility
  • src/Agent/AgentAlpha/Services/TaskExecutor.cs - Added session initialization and loop detection
  • src/Agent/AgentAlpha/Services/ConversationManager.cs - Added repetitive response detection
  • src/Agent/AgentAlpha/Interfaces/IConversationManager.cs - Added repetition detection interface

The AgentAlpha GitHub PR review workflow should now execute successfully without the reported errors.

Fixes #65.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 25, 2025 05:29
…vity logging

Co-authored-by: johnkord <16021727+johnkord@users.noreply.github.com>
Co-authored-by: johnkord <16021727+johnkord@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix the bugs identified in logs here Fix OpenAI API errors, session logging warnings, and infinite loops in AgentAlpha Jun 25, 2025
Copilot AI requested a review from johnkord June 25, 2025 05:36
@johnkord johnkord marked this pull request as ready for review June 25, 2025 12:21
@johnkord johnkord merged commit 0567e53 into main Jun 25, 2025
@johnkord johnkord deleted the copilot/fix-65 branch June 25, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix the bugs identified in logs here

2 participants