Skip to content

Commit a044c88

Browse files
committed
fix planner instructions, and api endpoint
1 parent 0d959c6 commit a044c88

File tree

4 files changed

+36
-53
lines changed

4 files changed

+36
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,4 @@ __pycache__/
458458
*.whl
459459
!autogen_core-0.3.dev0-py3-none-any.whl
460460
.azure
461+
.github/copilot-instructions.md

src/backend/app_kernel.py

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
logging.info("Added health check middleware")
8484

8585

86-
@app.post("/input_task")
86+
@app.post("/api/input_task")
8787
async def input_task_endpoint(input_task: InputTask, request: Request):
8888
"""
8989
Receive the initial input task from the user.
@@ -175,7 +175,7 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
175175
raise HTTPException(status_code=400, detail="Error creating plan")
176176

177177

178-
@app.post("/human_feedback")
178+
@app.post("/api/human_feedback")
179179
async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Request):
180180

181181
"""
@@ -268,7 +268,7 @@ async def human_feedback_endpoint(human_feedback: HumanFeedback, request: Reques
268268
}
269269

270270

271-
@app.post("/human_clarification_on_plan")
271+
@app.post("/api/human_clarification_on_plan")
272272
async def human_clarification_endpoint(
273273
human_clarification: HumanClarification, request: Request
274274
):
@@ -349,7 +349,7 @@ async def human_clarification_endpoint(
349349
}
350350

351351

352-
@app.post("/approve_step_or_steps")
352+
@app.post("/api/approve_step_or_steps")
353353
async def approve_step_endpoint(
354354
human_feedback: HumanFeedback, request: Request
355355
) -> Dict[str, str]:
@@ -453,7 +453,7 @@ async def approve_step_endpoint(
453453
return {"status": "All steps approved"}
454454

455455

456-
@app.get("/plans", response_model=List[PlanWithSteps])
456+
@app.get("/api/plans", response_model=List[PlanWithSteps])
457457
async def get_plans(
458458
request: Request, session_id: Optional[str] = Query(None)
459459
) -> List[PlanWithSteps]:
@@ -553,7 +553,7 @@ async def get_plans(
553553
return list_of_plans_with_steps
554554

555555

556-
@app.get("/steps/{plan_id}", response_model=List[Step])
556+
@app.get("/api/steps/{plan_id}", response_model=List[Step])
557557
async def get_steps_by_plan(plan_id: str, request: Request) -> List[Step]:
558558
"""
559559
Retrieve steps for a specific plan.
@@ -616,7 +616,7 @@ async def get_steps_by_plan(plan_id: str, request: Request) -> List[Step]:
616616
return steps
617617

618618

619-
@app.get("/agent_messages/{session_id}", response_model=List[AgentMessage])
619+
@app.get("/api/agent_messages/{session_id}", response_model=List[AgentMessage])
620620
async def get_agent_messages(session_id: str, request: Request) -> List[AgentMessage]:
621621
"""
622622
Retrieve agent messages for a specific session.
@@ -680,7 +680,7 @@ async def get_agent_messages(session_id: str, request: Request) -> List[AgentMes
680680
return agent_messages
681681

682682

683-
@app.delete("/messages")
683+
@app.delete("/api/messages")
684684
async def delete_all_messages(request: Request) -> Dict[str, str]:
685685
"""
686686
Delete all messages across sessions.
@@ -723,7 +723,7 @@ async def delete_all_messages(request: Request) -> Dict[str, str]:
723723
return {"status": "All messages deleted"}
724724

725725

726-
@app.get("/messages")
726+
@app.get("/api/messages")
727727
async def get_all_messages(request: Request):
728728
"""
729729
Retrieve all messages across sessions.
@@ -804,39 +804,6 @@ async def get_agent_tools():
804804
return []
805805

806806

807-
# Initialize the application when it starts
808-
@app.on_event("startup")
809-
async def startup_event():
810-
"""Initialize the application on startup.
811-
812-
This function runs when the FastAPI application starts up.
813-
It sets up the agent types and tool loaders so the first request is faster.
814-
"""
815-
# Log startup
816-
logging.info("Application starting up. Initializing agent factory...")
817-
818-
try:
819-
# Create a temporary session and user ID to pre-initialize agents
820-
# This ensures tools are loaded into the factory on startup
821-
temp_session_id = "startup-session"
822-
temp_user_id = "startup-user"
823-
824-
# Create a test agent to initialize the tool loading system
825-
# This will pre-load tool configurations into memory
826-
test_agent = await AgentFactory.create_agent(
827-
agent_type=AgentType.GENERIC,
828-
session_id=temp_session_id,
829-
user_id=temp_user_id
830-
)
831-
832-
# Clean up initialization resources
833-
AgentFactory.clear_cache(temp_session_id)
834-
logging.info("Agent factory successfully initialized")
835-
836-
except Exception as e:
837-
# Don't fail startup, but log the error
838-
logging.error(f"Error initializing agent factory: {e}")
839-
840807

841808
# Run the app
842809
if __name__ == "__main__":

src/backend/kernel_agents/planner_agent.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,17 @@ async def async_init(self) -> None:
147147
"""
148148
try:
149149
logging.info("Initializing PlannerAgent from async init azure AI Agent")
150-
# Create the Azure AI Agent using AppConfig
150+
151+
# Generate instructions as a string rather than returning an object
152+
# We'll use a blank input since this is just for initialization
153+
instruction_args = self._generate_instruction("")
154+
instructions = self._get_template().format(**instruction_args)
155+
156+
# Create the Azure AI Agent using AppConfig with string instructions
151157
self._azure_ai_agent = await config.create_azure_ai_agent(
152158
kernel=self._kernel,
153159
agent_name="PlannerAgent",
154-
instructions=self._generate_instruction(""),
160+
instructions=instructions, # Pass the formatted string, not an object
155161
temperature=0.0
156162
)
157163
logging.info("Successfully created Azure AI Agent for PlannerAgent")
@@ -311,8 +317,11 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
311317
logging.debug(f"Input: {input_task}")
312318
logging.debug(f"Available agents: {self._available_agents}")
313319

314-
instruction = self._generate_instruction(input_task.description)
320+
# Get template variables as a dictionary
321+
args = self._generate_instruction(input_task.description)
315322

323+
# Format the template with the arguments
324+
instruction = self._get_template().format(**args)
316325
logging.info(f"Generated instruction: {instruction}")
317326
# Log the input task for debugging
318327
logging.info(f"Creating plan for task: '{input_task.description}'")
@@ -651,14 +660,14 @@ async def _create_fallback_plan_from_text(self, input_task: InputTask, text_cont
651660

652661
return plan, steps
653662

654-
def _generate_instruction(self, objective: str) -> str:
663+
def _generate_instruction(self, objective: str) -> any:
655664
"""Generate instruction for the LLM to create a plan.
656665
657666
Args:
658667
objective: The user's objective
659668
660669
Returns:
661-
Instruction string for the LLM
670+
Dictionary containing the variables to populate the template
662671
"""
663672
# Create a list of available agents
664673
agents_str = ", ".join(self._available_agents)
@@ -766,11 +775,16 @@ def _generate_instruction(self, objective: str) -> str:
766775
# Convert the tools list to a string representation
767776
tools_str = str(tools_list)
768777

769-
return args
778+
# Return a dictionary with template variables
779+
return {
780+
"objective": objective,
781+
"agents_str": agents_str,
782+
"tools_str": tools_str,
783+
}
770784

771785
def _get_template(self):
772786
"""Generate the instruction template for the LLM."""
773-
# Build the instruction, avoiding backslashes in f-string expressions
787+
# Build the instruction with proper format placeholders for .format() method
774788

775789
instruction_template = """
776790
You are the Planner, an AI orchestrator that manages a group of AI agents to accomplish tasks.
@@ -782,13 +796,13 @@ def _get_template(self):
782796
These actions are passed to the specific agent. Make sure the action contains all the information required for the agent to execute the task.
783797
784798
Your objective is:
785-
{{$objective}}
799+
{objective}
786800
787801
The agents you have access to are:
788-
{{$agents_str}}
802+
{agents_str}
789803
790804
These agents have access to the following functions:
791-
{{$tools_str}}
805+
{tools_str}
792806
793807
IMPORTANT AGENT SELECTION GUIDANCE:
794808
- HrAgent: ALWAYS use for ALL employee-related tasks like onboarding, hiring, benefits, payroll, training, employee records, ID cards, mentoring, background checks, etc.
@@ -816,7 +830,7 @@ def _get_template(self):
816830
817831
Limit the plan to 6 steps or less.
818832
819-
Choose from {{$agents_str}} ONLY for planning your steps.
833+
Choose from {agents_str} ONLY for planning your steps.
820834
821835
"""
822836
return instruction_template

src/frontend/frontend_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
def get_config():
3030
backend_url = html.escape(os.getenv("BACKEND_API_URL", "http://localhost:8000"))
3131
auth_enabled = html.escape(os.getenv("AUTH_ENABLED", "True"))
32+
backend_url = backend_url + "/api"
3233
return f'''
3334
const BACKEND_API_URL = "{backend_url}";
3435
const AUTH_ENABLED = "{auth_enabled}";

0 commit comments

Comments
 (0)