@WillemdeJongh I was using v1.2.15 earlier. I see after v1.2.16, some improvement in teams got rolled out.
team.py
def get_loan_upselling_team(session_id:str=None, user_id:str=None) -> Team:
loan_upselling_team: Team = Team(
name="Loan Upselling team.",
user_id=user_id,
mode="coordinate",
session_id=session_id,
session_state={"state": "running"},
storage=session_db,
memory=common_memory,
model=azure_openai_model,
members=[sales_agent, verification_agent, decision_making_agent],
description="A team of agents handling customer queries for personal loan processes at Horizon Financial.",
instructions=
"""
General Instructions:
1. Please read the session_summary if provided in team context to know about past interactions with the user.
2. You can only handle queries for Personal loan. Other types of loan are out of your area of expertise.
3. Participating agents can ask you to gather customer input on their behalf that they need to provide response to customer query.
4. After taking user input, please provide that user input back to that agent which has asked you to gather that from the user.
5. Note down important user data like customer_id, name etc so that you can recall these data later on and provide these as input when required by other tool calls. You should persist this data in long term memory as well.
6. If you feel user input is important and could be reused in future tool calls, please save those data in session_data so that you don't need to ask same details twice with user and every participating agent has access to this data.
7. Tool call response of participating agent might contain information about next session to be updated. If this data exists, please update session state accordingly.
8. Along with deciding which tool to make, also please decide the session state after tool call would have been executed. Use `update_session_state` to update session state along with each tool call based on the following rules:
- if goal is not achieved and conversation is still going on, then session state should be `running`.
- if goal is achieved, then session state should be `completed`.
- if async tool call is made or you are waiting for response from some third party, then session state should be `waiting_async_tool`
- if action is pending on the user, then session state should be `pending_on_user`
- if any exception happens, then session state should be `disconnected`.
"""
,
success_criteria="""
Following is the success criteria:
- customer is satisfied with the response and his query is resolved.
- customer has no further query to ask.
- customer no longer wishes to continue the conversation..
- customer is no longer interested in the loan offers.
- customer loan application process is either approved or declined.
""",
add_context=True,
context={"session_id":session_id},
add_state_in_messages=True,
# add_datetime_to_instructions=True,
enable_agentic_context=True,
share_member_interactions=True,
read_team_history=True,
enable_team_history=True,
show_tool_calls=True,
show_members_responses=True,
debug_mode=True,
num_of_interactions_from_history=10,
# new params support in v1.3
enable_agentic_memory=True,
enable_user_memories=True,
enable_session_summaries=True
)
loan_upselling_team.tools = [TeamToolkit(loan_upselling_team)]
return loan_upselling_team
team_toolkit:
class TeamToolkit(Toolkit):
name = "team_toolkit"
instructions = """
Please use `update_session_state` after each team run to update current session state.
"""
def __init__(self, team: Team|None):
super().__init__(name="team_toolkit", instructions=self.instructions, add_instructions=True)
self.team = team
self.register(self.update_session_state)
def update_session_state(self, current_session_state:str, new_session_state:str) -> str:
"""updates the team's session state based on following rules:
- if goal is not achieved and conversation is still going on, then session state should be `running`.
- if goal is achieved, then session state should be `completed`.
- if async tool call is made, then session state should be `waiting_async_tool`.
- if action is pending on the user, then session state should be `pending_on_user`.
- if any exception happens, then session state should be `disconnected`.
Args:
current_session_state: Current session state
new_session_state: session state to be updated
Returns:
session_state: New team session state
"""
self.team.session_state = {"state": new_session_state}
return f"Session state: {new_session_state} saved."
sales_agent.py:
sales_agent = Agent(
agent_id="sales-agent",
name="Sales Agent",
model=azure_openai_model,
description="You are a sales assistant for Horizon Financial that engages customers with loan offers.",
goal="Present pre-approved loan offers and assist with general loan-related queries.",
instructions=[
"""
Workflow:
1. First gather basic details like customer_id from the customer using tool `get_customer_data`.
2. If customer is interested in the loans, present loan offers for the customer using the data received from `get_customer_data`.
3. You can use `calculate_emi` tool to handle queries from customer related to monthly EMIs.
4. You can use `get_recommendation_similar_customers` tool for providing offers based on similar customer preferences.
5. If customer is interested in applying for loan, first verify this eligibility and then identity via Verification agent.
6. After successful verification, ask customer's PAN card for verification. Submit the request to CRM and wait for response.
7. After successful pan verification, send online application link to customer via email. Once user fills the form, we will move forward with the conversation.
8. After successful form submission, use decision making agent to take a decision on customer's loan application.
General instructions:
1. You are a friendly sales assistant for Horizon Financial.
2. You will greet the customer and take customer details before initiating a conversation with the user.
3. If you need any input from user to run tool calls, please ask team leader to gather that information for you.
4. Use the provided tool calls to retrieve customer data, calculate EMIs or find loan offer recommendations from similar customers.
"""
],
tools=[SalesToolkit()],
read_chat_history=True,
read_tool_call_history=True,
add_history_to_messages=True,
num_history_responses=10,
add_state_in_messages=True,
memory=common_memory,
add_context=True,
add_memory_references=True,
add_session_summary_references=True,
# show_tool_calls=True,
# markdown=True,
# add_name_to_instructions=True,
# debug_mode=True,
)
Here are the few snippets from my code. Let me know if you need more input from me. I would request you to go through all issues that I’ve spoke of in this thread. Please refer my screenshots for the more context.
CC @Dirk
EDIT:
@WillemdeJongh @Dirk as I asked in previous thread as well, why don’t tool calls have a description in system prompt. It was there previosuly, right ? If I’m not mistaken. Could this be the reason for the drop in response quality, not calling tools properly to be specific.