fix: Agent/workflow bugs - CrewAI config, AutoGen revision
Team 2: Agent & Workflow Repair Crew Fixed: - #5: CrewAI LLM factory now properly uses provider/model params - Supports openai, anthropic, and minimax - Raises error for unknown providers instead of silently using OpenAI - Validates API keys are present - #2: AutoGen critique now actually revises chapters - iterate_chapter() now applies revision suggestions - Uses Writer agent to revise based on critique feedback - Returns revised_content in the result
This commit is contained in:
@@ -240,16 +240,58 @@ End with a final verdict: APPROVED, MINOR_REVISIONS, or MAJOR_REVISIONS.
|
|||||||
# Check if approved
|
# Check if approved
|
||||||
if critique["approved"]:
|
if critique["approved"]:
|
||||||
print(f" ✅ Chapter {chapter_num} approved!")
|
print(f" ✅ Chapter {chapter_num} approved!")
|
||||||
return critique
|
return {
|
||||||
|
**critique,
|
||||||
|
"revised_content": current_content,
|
||||||
|
}
|
||||||
|
|
||||||
# If not approved and have more iterations, continue
|
# Not approved - get revision suggestions and apply them
|
||||||
if iteration < max_iterations:
|
if iteration < max_iterations:
|
||||||
print(f" 📝 Score: {critique['overall_score']:.2f} - continuing...")
|
print(f" 📝 Score: {critique['overall_score']:.2f} - applying revisions...")
|
||||||
# In production: pass feedback to writer agent for revision
|
|
||||||
|
|
||||||
# Return last critique
|
# Use the Writer agent to revise based on critique
|
||||||
|
revision_suggestions = critique.get("summary", "")[:2000]
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Request revision from Writer agent
|
||||||
|
revision_request = f"""Revise Chapter {chapter_num} based on critique feedback.
|
||||||
|
|
||||||
|
## Current Chapter Content:
|
||||||
|
{current_content[:3000]}...
|
||||||
|
|
||||||
|
## Critique Feedback:
|
||||||
|
{revision_suggestions}
|
||||||
|
|
||||||
|
## Your Task:
|
||||||
|
Revise the chapter to address the weaknesses identified in the critique.
|
||||||
|
Preserve the strengths. Improve the story, pacing, and prose.
|
||||||
|
"""
|
||||||
|
# Use the writer agent to revise
|
||||||
|
revision_result = self.agents["writer"].initiate_chat(
|
||||||
|
self.manager,
|
||||||
|
message=revision_request,
|
||||||
|
summary_method="reflection_with_llm",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Extract revised content from the chat
|
||||||
|
if hasattr(revision_result, 'chat_history'):
|
||||||
|
# Get the last response as revised content
|
||||||
|
revised = revision_result.chat_history[-1].get('content', '') if revision_result.chat_history else current_content
|
||||||
|
if revised and len(revised) > 100:
|
||||||
|
current_content = revised
|
||||||
|
print(f" ✏️ Revision applied, new length: {len(current_content)} chars")
|
||||||
|
else:
|
||||||
|
print(f" ⚠️ No valid revision received, keeping current content")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f" ⚠️ Revision failed: {e}, continuing with current content")
|
||||||
|
|
||||||
|
# Return last critique with final content
|
||||||
print(f" ⚠️ Max iterations reached")
|
print(f" ⚠️ Max iterations reached")
|
||||||
return critique
|
return {
|
||||||
|
**critique,
|
||||||
|
"revised_content": current_content,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def create_critique_crew(
|
def create_critique_crew(
|
||||||
|
|||||||
@@ -18,30 +18,34 @@ def get_crewai_llm(provider: str = "openai", model: str = "gpt-4o") -> LLM:
|
|||||||
"""Get a CrewAI LLM instance.
|
"""Get a CrewAI LLM instance.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
provider: LLM provider (openai, anthropic, etc.)
|
provider: LLM provider (openai, anthropic, minimax)
|
||||||
model: Model name
|
model: Model name
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Configured CrewAI LLM
|
Configured CrewAI LLM
|
||||||
"""
|
"""
|
||||||
api_key = os.environ.get("OPENAI_API_KEY")
|
# Get API key based on provider
|
||||||
|
|
||||||
if provider == "openai":
|
if provider == "openai":
|
||||||
return LLM(
|
api_key = os.environ.get("OPENAI_API_KEY")
|
||||||
model="openai/" + model,
|
model_name = f"openai/{model}"
|
||||||
api_key=api_key,
|
|
||||||
)
|
|
||||||
elif provider == "anthropic":
|
elif provider == "anthropic":
|
||||||
return LLM(
|
api_key = os.environ.get("ANTHROPIC_API_KEY")
|
||||||
model="anthropic/" + model,
|
model_name = f"anthropic/{model}"
|
||||||
api_key=os.environ.get("ANTHROPIC_API_KEY"),
|
elif provider == "minimax":
|
||||||
)
|
api_key = os.environ.get("MINIMAX_API_KEY")
|
||||||
|
# MiniMax model format
|
||||||
|
model_name = f"minimax/{model}"
|
||||||
else:
|
else:
|
||||||
# Default to OpenAI
|
# Unknown provider - raise error instead of silently using OpenAI
|
||||||
return LLM(
|
raise ValueError(f"Unknown LLM provider: {provider}. Use: openai, anthropic, or minimax")
|
||||||
model="openai/gpt-4o",
|
|
||||||
api_key=api_key,
|
if not api_key:
|
||||||
)
|
raise ValueError(f"API key not found for provider: {provider}")
|
||||||
|
|
||||||
|
return LLM(
|
||||||
|
model=model_name,
|
||||||
|
api_key=api_key,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpusCrew:
|
class OpusCrew:
|
||||||
|
|||||||
Reference in New Issue
Block a user