Skip to content

Commit 38c6eae

Browse files
pyLint issues fixed
1 parent 75273af commit 38c6eae

File tree

14 files changed

+179
-167
lines changed

14 files changed

+179
-167
lines changed

src/backend/agents/agentutils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import json
22

3-
from autogen_core.components.models import (AssistantMessage,
4-
AzureOpenAIChatCompletionClient)
3+
from autogen_core.components.models import (
4+
AssistantMessage,
5+
AzureOpenAIChatCompletionClient,
6+
)
57
from pydantic import BaseModel
68

79
from context.cosmos_memory import CosmosBufferedChatCompletionContext
8-
from models.messages import InputTask, PlanStatus, Step, StepStatus
10+
from models.messages import Step
911

1012
common_agent_system_message = "If you do not have the information for the arguments of the function you need to call, do not call the function. Instead, respond back to the user requesting further information. You must not hallucinate or invent any of the information used as arguments in the function. For example, if you need to call a function that requires a delivery address, you must not generate 123 Example St. You must skip calling functions and return a clarification message along the lines of: Sorry, I'm missing some information I need to help you with that. Could you please provide the delivery address so I can do that for you?"
1113

@@ -27,7 +29,7 @@ class FSMStateAndTransition(BaseModel):
2729
identifiedTargetState: str
2830
identifiedTargetTransition: str
2931

30-
cosmos = CosmosBufferedChatCompletionContext(session_id or "",user_id)
32+
cosmos = CosmosBufferedChatCompletionContext(session_id or "", user_id)
3133
combined_LLM_messages = [
3234
AssistantMessage(content=step.action, source="GroupChatManager")
3335
]

src/backend/agents/base_agent.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33

44
from autogen_core.base import AgentId, MessageContext
55
from autogen_core.components import RoutedAgent, message_handler
6-
from autogen_core.components.models import (AssistantMessage,
7-
AzureOpenAIChatCompletionClient,
8-
LLMMessage, SystemMessage,
9-
UserMessage)
6+
from autogen_core.components.models import (
7+
AssistantMessage,
8+
AzureOpenAIChatCompletionClient,
9+
LLMMessage,
10+
SystemMessage,
11+
UserMessage,
12+
)
1013
from autogen_core.components.tool_agent import tool_agent_caller_loop
1114
from autogen_core.components.tools import Tool
1215

1316
from context.cosmos_memory import CosmosBufferedChatCompletionContext
14-
from models.messages import (ActionRequest, ActionResponse,
15-
AgentMessage, Step, StepStatus)
17+
from models.messages import (
18+
ActionRequest,
19+
ActionResponse,
20+
AgentMessage,
21+
Step,
22+
StepStatus,
23+
)
1624
from azure.monitor.events.extension import track_event
1725

26+
1827
class BaseAgent(RoutedAgent):
1928
def __init__(
2029
self,
@@ -95,7 +104,7 @@ async def handle_action_request(
95104
step_id=message.step_id,
96105
)
97106
)
98-
107+
99108
track_event(
100109
"Base agent - Added into the cosmos",
101110
{
@@ -107,7 +116,7 @@ async def handle_action_request(
107116
"step_id": message.step_id,
108117
},
109118
)
110-
119+
111120
except Exception as e:
112121
logging.exception(f"Error during LLM call: {e}")
113122
track_event(
@@ -121,14 +130,14 @@ async def handle_action_request(
121130
"step_id": message.step_id,
122131
},
123132
)
124-
133+
125134
return
126135
print(f"Task completed: {result}")
127136

128137
step.status = StepStatus.completed
129138
step.agent_reply = result
130139
await self._model_context.update_step(step)
131-
140+
132141
track_event(
133142
"Base agent - Updated step and updated into the cosmos",
134143
{

src/backend/agents/generic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from agents.base_agent import BaseAgent
99
from context.cosmos_memory import CosmosBufferedChatCompletionContext
1010

11+
1112
async def dummy_function() -> str:
1213
# This is a placeholder function, for a proper Azure AI Search RAG process.
1314

src/backend/agents/group_chat_manager.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
from context.cosmos_memory import CosmosBufferedChatCompletionContext
1313
from models.messages import (
1414
ActionRequest,
15-
ActionResponse,
1615
AgentMessage,
17-
ApprovalRequest,
1816
BAgentType,
1917
HumanFeedback,
2018
HumanFeedbackStatus,
2119
InputTask,
2220
Plan,
23-
PlanStatus,
2421
Step,
2522
StepStatus,
2623
)
@@ -291,12 +288,10 @@ async def _execute_step(self, session_id: str, step: Step):
291288
agent=step.agent,
292289
)
293290
logging.info(f"Sending ActionRequest to {step.agent.value}")
294-
291+
295292
if step.agent != "":
296293
agent_name = step.agent.value
297-
formatted_agent = re.sub(
298-
r"([a-z])([A-Z])", r"\1 \2", agent_name
299-
)
294+
formatted_agent = re.sub(r"([a-z])([A-Z])", r"\1 \2", agent_name)
300295
else:
301296
raise ValueError(f"Check {step.agent} is missing")
302297

src/backend/agents/human.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
import logging
33

44
from autogen_core.base import AgentId, MessageContext
5-
from autogen_core.components import (RoutedAgent, default_subscription,
6-
message_handler)
5+
from autogen_core.components import RoutedAgent, default_subscription, message_handler
76

87
from context.cosmos_memory import CosmosBufferedChatCompletionContext
98
from models.messages import (
109
ApprovalRequest,
1110
HumanFeedback,
12-
HumanClarification,
13-
HumanFeedbackStatus,
1411
StepStatus,
1512
AgentMessage,
1613
Step,
@@ -23,7 +20,7 @@ class HumanAgent(RoutedAgent):
2320
def __init__(
2421
self,
2522
memory: CosmosBufferedChatCompletionContext,
26-
user_id:str,
23+
user_id: str,
2724
group_chat_manager_id: AgentId,
2825
) -> None:
2926
super().__init__("HumanAgent")
@@ -83,7 +80,7 @@ async def handle_step_feedback(
8380
)
8481
)
8582
logging.info(f"HumanAgent sent approval request for step: {step}")
86-
83+
8784
track_event(
8885
f"Human Agent - Approval request sent for step {step} and added into the cosmos",
8986
{

src/backend/agents/planner.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
from typing import List, Optional
66

77
from autogen_core.base import MessageContext
8-
from autogen_core.components import (RoutedAgent, default_subscription,
9-
message_handler)
10-
from autogen_core.components.models import (AzureOpenAIChatCompletionClient,
11-
LLMMessage, UserMessage)
8+
from autogen_core.components import RoutedAgent, default_subscription, message_handler
9+
from autogen_core.components.models import (
10+
AzureOpenAIChatCompletionClient,
11+
LLMMessage,
12+
UserMessage,
13+
)
1214
from pydantic import BaseModel
1315

1416
from context.cosmos_memory import CosmosBufferedChatCompletionContext
1517
from models.messages import (
16-
ActionRequest,
1718
AgentMessage,
1819
HumanClarification,
1920
BAgentType,
20-
HumanFeedback,
2121
InputTask,
2222
Plan,
2323
PlanStatus,
@@ -28,6 +28,7 @@
2828
from typing import Optional
2929
from azure.monitor.events.extension import track_event
3030

31+
3132
@default_subscription
3233
class PlannerAgent(RoutedAgent):
3334
def __init__(
@@ -72,7 +73,7 @@ async def handle_input_task(self, message: InputTask, ctx: MessageContext) -> Pl
7273
)
7374
)
7475
logging.info(f"Plan generated: {plan.summary}")
75-
76+
7677
track_event(
7778
f"Planner - Generated a plan with {len(steps)} steps and added plan into the cosmos",
7879
{
@@ -99,7 +100,7 @@ async def handle_input_task(self, message: InputTask, ctx: MessageContext) -> Pl
99100
logging.info(
100101
f"Additional information requested: {plan.human_clarification_request}"
101102
)
102-
103+
103104
track_event(
104105
"Planner - Additional information requested and added into the cosmos",
105106
{
@@ -136,7 +137,7 @@ async def handle_plan_clarification(
136137
step_id="",
137138
)
138139
)
139-
140+
140141
track_event(
141142
"Planner - Store HumanAgent clarification and added into the cosmos",
142143
{
@@ -146,7 +147,7 @@ async def handle_plan_clarification(
146147
"source": "HumanAgent",
147148
},
148149
)
149-
150+
150151
await self._memory.add_item(
151152
AgentMessage(
152153
session_id=message.session_id,
@@ -158,7 +159,7 @@ async def handle_plan_clarification(
158159
)
159160
)
160161
logging.info("Plan updated with HumanClarification.")
161-
162+
162163
track_event(
163164
"Planner - Updated with HumanClarification and added into the cosmos",
164165
{
@@ -170,7 +171,6 @@ async def handle_plan_clarification(
170171
)
171172

172173
def _generate_instruction(self, objective: str) -> str:
173-
174174
# TODO FIX HARDCODED AGENT NAMES AT BOTTOM OF PROMPT
175175
agents = ", ".join([agent for agent in self._available_agents])
176176

@@ -252,18 +252,18 @@ class StructuredOutputPlan(BaseModel):
252252
# Parse the LLM response
253253
parsed_result = json.loads(content)
254254
structured_plan = StructuredOutputPlan(**parsed_result)
255-
255+
256256
if not structured_plan.steps:
257257
track_event(
258258
"Planner agent - No steps found",
259259
{
260-
"session_id":self._session_id,
261-
"user_id":self._user_id,
262-
"initial_goal":structured_plan.initial_goal,
263-
"overall_status":"No steps found",
264-
"source":"PlannerAgent",
265-
"summary":structured_plan.summary_plan_and_steps,
266-
"human_clarification_request":structured_plan.human_clarification_request
260+
"session_id": self._session_id,
261+
"user_id": self._user_id,
262+
"initial_goal": structured_plan.initial_goal,
263+
"overall_status": "No steps found",
264+
"source": "PlannerAgent",
265+
"summary": structured_plan.summary_plan_and_steps,
266+
"human_clarification_request": structured_plan.human_clarification_request,
267267
},
268268
)
269269
raise ValueError("No steps found")
@@ -281,7 +281,7 @@ class StructuredOutputPlan(BaseModel):
281281
)
282282
# Store the plan in memory
283283
await self._memory.add_plan(plan)
284-
284+
285285
track_event(
286286
"Planner - Initial plan and added into the cosmos",
287287
{

0 commit comments

Comments
 (0)