Skip to content

Handling service session memory in Agents SDK #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dzhouEV opened this issue Mar 19, 2025 · 2 comments
Closed

Handling service session memory in Agents SDK #248

dzhouEV opened this issue Mar 19, 2025 · 2 comments
Labels
question Question about using the SDK

Comments

@dzhouEV
Copy link

dzhouEV commented Mar 19, 2025

Hi,

What is the best way to implement something like the customer service example in a FastAPI service? Specifically, what is the best way to handle session memory in the Agents SDK?

Retrieving the traces by group_id seems like one way to do it since that gets stored in the platform but I couldn't find a way to get those programmatically. We could always use other OSS to cache the result.to_input_list() output but wondering if there was a built-in solution.

@dzhouEV dzhouEV added the question Question about using the SDK label Mar 19, 2025
@rm-openai
Copy link
Collaborator

Generally recommend storing the messages in a database. pseudocode:

@app.post(/chat)
def send_msg(message: str, uid:str, chat_id: str):
  previous_messages = db.get(uid, chat_id, count=20)
  previous_messages.append({"role": "user", "content": message})

  result = Runner.run(...)
  db.save(uid, chat_id, result.new_items)
  
  return result.new_items

@dzhouEV dzhouEV closed this as completed Mar 20, 2025
@tzookb
Copy link

tzookb commented Mar 27, 2025

thanks @rm-openai

I do notice the result from a run.new_items is a list of

RunItem: TypeAlias = Union[
    MessageOutputItem,
    HandoffCallItem,
    HandoffOutputItem,
    ToolCallItem,
    ToolCallOutputItem,
    ReasoningItem,
]

but for calling run, I need to pass a list of:
list[TResponseInputItem]

ResponseInputItemParam: TypeAlias = Union[
    EasyInputMessageParam,
    Message,
    ResponseOutputMessageParam,
    ResponseFileSearchToolCallParam,
    ResponseComputerToolCallParam,
    ComputerCallOutput,
    ResponseFunctionWebSearchParam,
    ResponseFunctionToolCallParam,
    FunctionCallOutput,
    ResponseReasoningItemParam,
    ItemReference,
]

I want to store data in the DB, but I don't want to blindly store the items. I want to have our own json struct so I can convert to the above objects.
But to which are we aiming for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

3 participants