Skip to content

ValueError("Failed to parse ledger information after multiple retries.") When using MagenticOne Orchestrator with gpt-4.1-mini #6599

@vamsithumma2812

Description

@vamsithumma2812

What happened?

Hello,

I'm facing an issue when I use MagenticOne Orchestrator with gpt-4.1-mini model -

Error
In file ".venv\Lib\site-packages\autogen_agentchat\teams_group_chat_magentic_one_magentic_one_orchestrator.py", line 353

    raise ValueError("Failed to parse ledger information after multiple retries.")

Sometimes the multiagent workflow is working fine without any errors but sometimes throwing this error.

I'm passing this in model_client for MagenticOne Orchestrator and all of my agents-

model - "gpt-4.1-mini"
model info - {
        "vision": False,
        "json_output": True,
        "function_calling": True,
        "family": "gpt-4.1",
        "structured_output": True
    }

Is this an issue from autogen magenticone module, am I passing correct configurations? I think I haven't faced this issue when I used 'gpt-4o-mini' model.

Does LLM is generating content like this, and the code is not flexible to parse this kind of json?

{
  "content": "```json\n{...}\n```"
}

This is the code snippet for the file where the error is thrown, I think the line progress_ledger = json.loads(ledger_str) is not capable to handle the json string if we get model output with prefix json\n{...}\n

async def _orchestrate_step(self, cancellation_token: CancellationToken) -> None:
    """Implements the inner loop of the orchestrator and selects next speaker."""
    # Check if we reached the maximum number of rounds
    if self._max_turns is not None and self._n_rounds > self._max_turns:
	    await self._prepare_final_answer("Max rounds reached.", cancellation_token)
	    return
    self._n_rounds += 1
    
    # Update the progress ledger
    context = self._thread_to_context()
    
    progress_ledger_prompt = self._get_progress_ledger_prompt(
	    self._task, self._team_description, self._participant_names
    )
    context.append(UserMessage(content=progress_ledger_prompt, source=self._name))
    progress_ledger: Dict[str, Any] = {}
    assert self._max_json_retries > 0
    key_error: bool = False
    for _ in range(self._max_json_retries):
	    response = await self._model_client.create(self._get_compatible_context(context), json_output=True)
	    ledger_str = response.content
	    try:
		    assert isinstance(ledger_str, str)
		    progress_ledger = json.loads(ledger_str)
    
		    # If the team consists of a single agent, deterministically set the next speaker
		    if len(self._participant_names) == 1:
			    progress_ledger["next_speaker"] = {
				    "reason": "The team consists of only one agent.",
				    "answer": self._participant_names[0],
			    }
    
		    # Validate the structure
		    required_keys = [
			    "is_request_satisfied",
			    "is_progress_being_made",
			    "is_in_loop",
			    "instruction_or_question",
			    "next_speaker",
		    ]
    
		    key_error = False
		    for key in required_keys:
			    if (
				    key not in progress_ledger
				    or not isinstance(progress_ledger[key], dict)
				    or "answer" not in progress_ledger[key]
				    or "reason" not in progress_ledger[key]
			    ):
				    key_error = True
				    break
    
		    # Validate the next speaker if the task is not yet complete
		    if (
			    not progress_ledger["is_request_satisfied"]["answer"]
			    and progress_ledger["next_speaker"]["answer"] not in self._participant_names
		    ):
			    key_error = True
			    break
    
		    if not key_error:
			    break
		    await self._log_message(f"Failed to parse ledger information, retrying: {ledger_str}")
	    except (json.JSONDecodeError, TypeError):
		    key_error = True
		    await self._log_message("Invalid ledger format encountered, retrying...")
		    continue

Is there any solution for this, help me to solve this error.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.5.7

Other library version.

No response

Model used

gpt-4.1-mini

Model provider

Azure OpenAI

Other model provider

No response

Python version

3.11

.NET version

None

Operating system

Windows

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions