Unable to update session state of Team object

I’m trying to update session state via tool call from Team leader. But it is not passing team object properly. I’m referring this documentation: Agent Session - Agno. Everytime team parameter has random dictionary, not actual team object that is deriving the conversation.

class TeamToolkit(Toolkit):
    name = "team_toolkit"

    def __init__(self):
        super().__init__(name="team_toolkit")
        self.register(self.update_session_state)

    def get_current_session_state(self, session_id:str) -> str|None:
        """Retrieves current session state. It can be one of following:
        - `completed`.
        - `waiting_async_tool`
        - `disconnected`
        - `running`

        Args:
            session_id: Session id

        Returns:
            str: session state
        """

        try:
            session = Session.objects.get(session_id=session_id)
        except Session.DoesNotExist:
            return "Session object does not exist as of now."

        session_state = session.session_data.get('session_state', {})
        state = session_state.get('state', None)

        print(session.session_data)
        print(session_state)
        print(state)
        return state

    def update_session_state(self, team:Team, 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 any exception happens, then session state should be `disconnected`

        Args:
            team: Agent Team
            current_session_state: Current session state
            new_session_state: session state to be updated

        Returns:
            session_state: New team session state
        """
        # state_dict = {'session_state': {'state': new_session_state}}
        #
        # session:Session = Session.objects.get(session_id=session_id)
        # new_session_data = {**session.session_data, **state_dict}
        #
        # print(session.session_data)
        # session.session_data = new_session_data
        # session.save(update_fields=['session_data'])
        # session.refresh_from_db()
        # print(session.session_data)
        team.session_state = {"state": new_session_state}

        # print(f"Session state: {new_session_state} saved.")
        return f"Session state: {new_session_state} saved."

@Monali @Monali @kausmos @Dirk @ayush could you guys please assist me. I’ll really appreciate your help

Hey @MahorShekhar
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.

We are excited to know what you are building.

@monali could you guys please assist me with this ?

Basically I want to know how to update session state after each tool call so that I can keep track my conversation is at which step. As of now I’ve assigned team leader a toolkit to update session state via team.session_state="running". But in agent tool kits, i cannot access the team object, so how can I update team session state in participating agent’ s tool calls ?

Hi @MahorShekhar
Apologies, this has been fixed in version 1.2.16. It only works with agent as the name of the parameter (even if it is a Team that is passed).

I will specifically go test whether your example would work.

@Dirk did you mean I can pass Team leader object with name agent in participating agent’s tool calls as well ??

My question is how to update team session state in every tool call - be it team leader tool calls or participating agent tool calls. There has to be a standard and unified approach for maintaining session state across team leaders and team participants agents.

Hi @MahorShekhar
Agreed, we are working on a single solution for both.
There are options here:

  1. You can set share_member_interactions then all responses from calling team members will be shared with subsequent members. I know this isn’t exactly what you are looking for, but it might help.
  2. Here is an example where you can manipulate the session state in a tool call for an agent, here is the same kind of example for a team. The problem that we still have to solve, and you are very correct in saying this, the session_state is not shared between all the members of the team because they don’t share a session. This is something I am actively working on.

thank you so much @Dirk

I’m eagerly waiting for this update because without this capability, Agno can’t be used for solving complex use cases. Also I will be blocked until this update is rolled out :sweat_smile: as this session state management across tools is a required thing to continue my work.

Thanks for the feedback.
The examples I shared should cover your use-case right? Or do you require a single session_state that all members of the team can manipulate?

No @Dirk , I need that team member tool calls should have access to session state and we can update session state from every tool call, be it team or team members.

You are correct here -

do you require a single session_state that all members of the team can manipulate?

Ah I see. Yes others have also requested this. Working on it :+1: