Skip to content

Commit d06acd3

Browse files
committed
format files
1 parent ec28d83 commit d06acd3

File tree

10 files changed

+224
-181
lines changed

10 files changed

+224
-181
lines changed

src/backend/config_kernel.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import semantic_kernel as sk
55
from semantic_kernel.kernel import Kernel
6+
67
# Updated imports for compatibility
78
try:
89
# Try newer structure
@@ -15,6 +16,7 @@
1516
# Import AppConfig from app_config
1617
from app_config import config
1718

19+
1820
# This file is left as a lightweight wrapper around AppConfig for backward compatibility
1921
# All configuration is now handled by AppConfig in app_config.py
2022
class Config:
@@ -39,7 +41,9 @@ class Config:
3941
AZURE_AI_SUBSCRIPTION_ID = config.AZURE_AI_SUBSCRIPTION_ID
4042
AZURE_AI_RESOURCE_GROUP = config.AZURE_AI_RESOURCE_GROUP
4143
AZURE_AI_PROJECT_NAME = config.AZURE_AI_PROJECT_NAME
42-
AZURE_AI_AGENT_PROJECT_CONNECTION_STRING = config.AZURE_AI_AGENT_PROJECT_CONNECTION_STRING
44+
AZURE_AI_AGENT_PROJECT_CONNECTION_STRING = (
45+
config.AZURE_AI_AGENT_PROJECT_CONNECTION_STRING
46+
)
4347

4448
@staticmethod
4549
def GetAzureCredentials():
@@ -55,7 +59,7 @@ def GetCosmosDatabaseClient():
5559
def CreateKernel():
5660
"""Creates a new Semantic Kernel instance using the AppConfig implementation."""
5761
return config.create_kernel()
58-
62+
5963
@staticmethod
6064
def GetAIProjectClient():
6165
"""Get an AIProjectClient using the AppConfig implementation."""

src/backend/kernel_agents/agent_utils.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class FSMStateAndTransition(BaseModel):
1515
"""Model for state and transition in a finite state machine."""
16+
1617
identifiedTargetState: str
1718
identifiedTargetTransition: str
1819

@@ -25,61 +26,65 @@ async def extract_and_update_transition_states(
2526
kernel: sk.Kernel,
2627
) -> Optional[Step]:
2728
"""
28-
This function extracts the identified target state and transition from the LLM response and updates
29+
This function extracts the identified target state and transition from the LLM response and updates
2930
the step with the identified target state and transition. This is reliant on the agent_reply already being present.
30-
31+
3132
Args:
3233
step: The step to update
3334
session_id: The current session ID
3435
user_id: The user ID
3536
planner_dynamic_or_workflow: Type of planner
3637
kernel: The semantic kernel instance
37-
38+
3839
Returns:
3940
The updated step or None if extraction fails
4041
"""
4142
planner_dynamic_or_workflow = "workflow"
4243
if planner_dynamic_or_workflow == "workflow":
4344
cosmos = CosmosMemoryContext(session_id=session_id, user_id=user_id)
44-
45+
4546
# Create chat history for the semantic kernel completion
4647
messages = [
4748
{"role": "assistant", "content": step.action},
4849
{"role": "assistant", "content": step.agent_reply},
49-
{"role": "assistant", "content": "Based on the above conversation between two agents, I need you to identify the identifiedTargetState and identifiedTargetTransition values. Only return these values. Do not make any function calls. If you are unable to work out the next transition state, return ERROR."}
50+
{
51+
"role": "assistant",
52+
"content": "Based on the above conversation between two agents, I need you to identify the identifiedTargetState and identifiedTargetTransition values. Only return these values. Do not make any function calls. If you are unable to work out the next transition state, return ERROR.",
53+
},
5054
]
5155

5256
# Get the LLM response using semantic kernel
5357
completion_service = kernel.get_service("completion")
54-
58+
5559
try:
5660
completion_result = await completion_service.complete_chat_async(
5761
messages=messages,
58-
execution_settings={
59-
"response_format": {"type": "json_object"}
60-
}
62+
execution_settings={"response_format": {"type": "json_object"}},
6163
)
62-
64+
6365
content = completion_result
64-
66+
6567
# Parse the LLM response
6668
parsed_result = json.loads(content)
6769
structured_plan = FSMStateAndTransition(**parsed_result)
68-
70+
6971
# Update the step
7072
step.identified_target_state = structured_plan.identifiedTargetState
71-
step.identified_target_transition = structured_plan.identifiedTargetTransition
72-
73+
step.identified_target_transition = (
74+
structured_plan.identifiedTargetTransition
75+
)
76+
7377
await cosmos.update_step(step)
7478
return step
75-
79+
7680
except Exception as e:
7781
print(f"Error extracting transition states: {e}")
7882
return None
7983

84+
8085
# The commented-out functions below would be implemented when needed
8186
# async def set_next_viable_step_to_runnable(session_id):
8287
# pass
8388

8489
# async def initiate_replanning(session_id):
85-
# pass
90+
# pass

src/backend/kernel_agents/generic_agent.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from context.cosmos_memory_kernel import CosmosMemoryContext
99
from models.messages_kernel import AgentType
1010

11+
1112
class GenericAgent(BaseAgent):
1213
"""Generic agent implementation using Semantic Kernel."""
1314

@@ -25,7 +26,7 @@ def __init__(
2526
definition=None,
2627
) -> None:
2728
"""Initialize the Generic Agent.
28-
29+
2930
Args:
3031
kernel: The semantic kernel instance
3132
session_id: The current session identifier
@@ -43,17 +44,19 @@ def __init__(
4344
# Load the generic tools configuration
4445
config = self.load_tools_config("generic", config_path)
4546
tools = self.get_tools_from_config(kernel, "generic", config_path)
46-
47+
4748
# Use system message from config if not explicitly provided
4849
if not system_message:
49-
system_message = config.get("system_message",
50+
system_message = config.get(
51+
"system_message",
5052
"You are a generic agent. You are used to handle generic tasks that a general Large Language Model can assist with. "
5153
"You are being called as a fallback, when no other agents are able to use their specialised functions in order to solve "
52-
"the user's task. Summarize back to the user what was done.")
53-
54+
"the user's task. Summarize back to the user what was done.",
55+
)
56+
5457
# Use agent name from config if available
5558
agent_name = AgentType.GENERIC.value
56-
59+
5760
# Call the parent initializer
5861
super().__init__(
5962
agent_name=agent_name,
@@ -64,20 +67,20 @@ def __init__(
6467
tools=tools,
6568
system_message=system_message,
6669
client=client,
67-
definition=definition
70+
definition=definition,
6871
)
69-
72+
7073
# Explicitly inherit handle_action_request from the parent class
7174
# This is not technically necessary but makes the inheritance explicit
7275
async def handle_action_request(self, action_request_json: str) -> str:
7376
"""Handle an action request from another agent or the system.
74-
77+
7578
This method is inherited from BaseAgent but explicitly included here for clarity.
76-
79+
7780
Args:
7881
action_request_json: The action request as a JSON string
79-
82+
8083
Returns:
8184
A JSON string containing the action response
8285
"""
83-
return await super().handle_action_request(action_request_json)
86+
return await super().handle_action_request(action_request_json)

src/backend/kernel_agents/hr_agent.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from context.cosmos_memory_kernel import CosmosMemoryContext
88
from models.messages_kernel import AgentType
99

10+
1011
class HrAgent(BaseAgent):
1112
"""HR agent implementation using Semantic Kernel.
12-
13+
1314
This agent provides HR-related functions such as onboarding, benefits management,
1415
and employee administration. All tools are loaded from hr_tools.json.
1516
"""
@@ -28,7 +29,7 @@ def __init__(
2829
definition=None,
2930
) -> None:
3031
"""Initialize the HR Agent.
31-
32+
3233
Args:
3334
kernel: The semantic kernel instance
3435
session_id: The current session identifier
@@ -46,17 +47,17 @@ def __init__(
4647
# Load the HR tools configuration
4748
config = self.load_tools_config("hr", config_path)
4849
tools = self.get_tools_from_config(kernel, "hr", config_path)
49-
50+
5051
# Use system message from config if not explicitly provided
5152
if not system_message:
5253
system_message = config.get(
53-
"system_message",
54-
"You are an AI Agent. You have knowledge about HR (e.g., human resources), policies, procedures, and onboarding guidelines."
54+
"system_message",
55+
"You are an AI Agent. You have knowledge about HR (e.g., human resources), policies, procedures, and onboarding guidelines.",
5556
)
56-
57+
5758
# Use agent name from config if available
5859
agent_name = AgentType.HR.value
59-
60+
6061
super().__init__(
6162
agent_name=agent_name,
6263
kernel=kernel,
@@ -66,5 +67,5 @@ def __init__(
6667
tools=tools,
6768
system_message=system_message,
6869
client=client,
69-
definition=definition
70-
)
70+
definition=definition,
71+
)

src/backend/kernel_agents/marketing_agent.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from context.cosmos_memory_kernel import CosmosMemoryContext
88
from models.messages_kernel import AgentType
99

10+
1011
class MarketingAgent(BaseAgent):
1112
"""Marketing agent implementation using Semantic Kernel.
12-
13+
1314
This agent specializes in marketing strategies, campaign development,
1415
content creation, and market analysis. It can create effective marketing
1516
campaigns, analyze market trends, develop promotional content, and more.
@@ -30,7 +31,7 @@ def __init__(
3031
definition=None,
3132
) -> None:
3233
"""Initialize the Marketing Agent.
33-
34+
3435
Args:
3536
kernel: The semantic kernel instance
3637
session_id: The current session identifier
@@ -48,17 +49,17 @@ def __init__(
4849
# Load the marketing tools configuration
4950
config = self.load_tools_config("marketing", config_path)
5051
tools = self.get_tools_from_config(kernel, "marketing", config_path)
51-
52+
5253
# Use system message from config if not explicitly provided
5354
if not system_message:
5455
system_message = config.get(
55-
"system_message",
56-
"You are an AI Agent. You have knowledge about marketing, including campaigns, market research, and promotional activities."
56+
"system_message",
57+
"You are an AI Agent. You have knowledge about marketing, including campaigns, market research, and promotional activities.",
5758
)
58-
59+
5960
# Use agent name from config if available
6061
agent_name = AgentType.MARKETING.value
61-
62+
6263
super().__init__(
6364
agent_name=agent_name,
6465
kernel=kernel,
@@ -68,5 +69,5 @@ def __init__(
6869
tools=tools,
6970
system_message=system_message,
7071
client=client,
71-
definition=definition
72-
)
72+
definition=definition,
73+
)

src/backend/kernel_agents/procurement_agent.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from context.cosmos_memory_kernel import CosmosMemoryContext
88
from models.messages_kernel import AgentType
99

10+
1011
class ProcurementAgent(BaseAgent):
1112
"""Procurement agent implementation using Semantic Kernel.
12-
13+
1314
This agent specializes in purchasing, vendor management, supply chain operations,
1415
and inventory control. It can create purchase orders, manage vendors, track orders,
1516
and ensure efficient procurement processes.
@@ -29,7 +30,7 @@ def __init__(
2930
definition=None,
3031
) -> None:
3132
"""Initialize the Procurement Agent.
32-
33+
3334
Args:
3435
kernel: The semantic kernel instance
3536
session_id: The current session identifier
@@ -47,17 +48,17 @@ def __init__(
4748
# Load the procurement tools configuration
4849
config = self.load_tools_config("procurement", config_path)
4950
tools = self.get_tools_from_config(kernel, "procurement", config_path)
50-
51+
5152
# Use system message from config if not explicitly provided
5253
if not system_message:
5354
system_message = config.get(
54-
"system_message",
55-
"You are an AI Agent. You are able to assist with procurement enquiries and order items. If you need additional information from the human user asking the question in order to complete a request, ask before calling a function."
55+
"system_message",
56+
"You are an AI Agent. You are able to assist with procurement enquiries and order items. If you need additional information from the human user asking the question in order to complete a request, ask before calling a function.",
5657
)
57-
58+
5859
# Use agent name from config if available
5960
agent_name = AgentType.PROCUREMENT.value
60-
61+
6162
super().__init__(
6263
agent_name=agent_name,
6364
kernel=kernel,
@@ -67,5 +68,5 @@ def __init__(
6768
tools=tools,
6869
system_message=system_message,
6970
client=client,
70-
definition=definition
71-
)
71+
definition=definition,
72+
)

0 commit comments

Comments
 (0)