Agent Session State is not updating in the SQlite

I am trying to update the session state without tool calling ,

But after updating the session_state for once , it is updating the session_state in the SQlite storage , but the moment I want to update it again it is not updating the session_state in the SQlite.

For example in the attached screen shot it is only updating the session state to 6 and not updating to 11 when I used agent.session_state[‘counter’] +=5.

Does currently agents are only updating session_state with tool calling and not with any other functions ? Because I was working on another code and updating the session_state with tool calling and it was working there but here without tool calling it is not working.

Hi @gulfamtahir535
thanks for reaching out and supporting Agno!We’ve shared this with the team and are working through requests one by one—we’ll get back to you as soon as we can.We’ve just kicked off the Global Agent Hackathon , so things are a bit busier than usual. If you’re up for it, we’d love for you to join—it’s a great chance to build, win some exciting prizes and connect with the agent community!If it’s urgent, just let us know. Thanks for your patience!

hey @gulfamtahir535 can you please try this :

from agno.models.google.gemini import Gemini
from agno.storage.sqlite import SqliteStorage
from agno.tools.reasoning import ReasoningTools

agent = Agent(
    session_id="my_session",  # Fixed session ID for demo
    model=Gemini(id="gemini-1.5-flash-latest"),
    tools=[ReasoningTools(add_instructions=True)],
    storage=SqliteStorage(table_name="agent_sessasaions", db_file="tmp/user_agents.db"),
    # Initialize session state
    session_state={"counters": 0},
    instructions="Current counter value is: {counters}",
    add_state_in_messages=True,
    markdown=True
)
agent.session_state["counters"] += 6

agent.print_response("What is the current counter value?" , session_id="my_session")
agent.session_state ["counters"]+= 5
agent.write_to_storage(session_id="my_session")
agent.print_response("What is the current counter value?", session_id="my_session")

print(f"Final session state: {agent.session_state}")

i have added this agent.write_to_storage(session_id="my_session") it will update the session_state in sqlLite

and currently updating session_state with different functions is supported , can you please share the code for this issue

thanks :raising_hands:

@ayush Thank you for your reply.

Yes it is working now. I didn’t use the extra code which you mentioned.

Because while working with the tools to update the session_State I don’t need to use this line of code.

I will look much deeper into it. Thank you :slight_smile: