Skip to content

Commit

Permalink
Share a thread again
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Oct 7, 2024
1 parent 973309c commit d414920
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/chatbot/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,17 @@ async def schedule_memories(state: ChatState, config: RunnableConfig) -> None:
"""Prompt the bot to respond to the user, incorporating memories (if provided)."""
configurable = ChatConfigurable.from_runnable_config(config)
memory_client = get_client()
mem_thread_id = str(
uuid.uuid5(
uuid.NAMESPACE_URL,
configurable.mem_assistant_id + config["configurable"]["thread_id"],
)
)
await memory_client.threads.create(thread_id=mem_thread_id, if_exists="do_nothing")
await memory_client.runs.create(
# Generate a thread so we can run the memory service on a separate
# but consistent thread. This lets us cancel scheduled runs if
# a new message arrives to our chatbot before the memory service
# begins processing.
thread_id=mem_thread_id,
# We enqueue the memory formation process on the same thread.
# This means that IF this thread doesn't receive more messages before `after_seconds`,
# it will read from the shared state and extract memories for us.
# If a new request comes in for this thread before the scheduled run is executed,
# that run will be canceled, and a **new** one will be scheduled once
# this node is executed again.
thread_id=config["configurable"]["thread_id"],
# Rollback & cancel any scheduled runs for the target thread
# that haven't completed
multitask_strategy="rollback",
multitask_strategy="enqueue",
# This lets us "debounce" repeated requests to the memory graph
# if the user is actively engaging in a conversation
after_seconds=configurable.delay_seconds,
Expand Down

0 comments on commit d414920

Please sign in to comment.