what's the difference between session.close and se...
# ask-ai
n
what's the difference between session.close and session.aclose? why does agents-js not support aclose? Is it just async for python's asyncio?
t
Thanks for reaching out, Francisco. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — good question. You're asking about the difference between
session.close
and
session.aclose
, and why agents-js doesn't expose
aclose
— and whether
aclose
is specifically tied to Python's asyncio. Short answer •
aclose()
is the Python async-style close used in asyncio code; it is an awaitable that performs the close and waits for cleanup to complete. •
close()
in agents-js is the JavaScript/Node idiomatic equivalent that performs the same functional intent (shut down the session / disconnect the agent). Node/JS code uses
close()
rather than an
aclose
name. • The naming difference is due to language conventions, not a difference in capability: Python uses
aclose
for async context, while JavaScript uses
close()
and can be awaited if it returns a Promise. More detail • In Python:
aclose()
is an async method that you
await
so the runtime performs the shutdown and you don’t continue until cleanup is finished. There is also a non-blocking
shutdown()
option for graceful draining. • In agents-js (Node):
session.close()
is provided as the shutdown call. JavaScript does not follow the
a
prefix convention — asynchronous cleanup is expressed via returning a Promise or allowing the method to be `await`ed. So
close()
in JS serves the same role as
aclose()
in Python. If you want, tell me: • Which SDK you’re using (Python or agents-js) and whether you need example code for awaiting the close/shutdown flow — I can share a short snippet showing the recommended pattern. Sources: Job lifecycle | LiveKit Documentation
n
what's the difference between session.close() and session.shutdown()
t
Thanks — I’m responding to your question about the difference between
session.close()
and
session.shutdown()
. Short answer •
session.close()
immediately closes the session and disconnects the agent from the room. •
session.shutdown()
is a non-blocking, graceful shutdown that can optionally drain pending work (for example, finish pending speech) before completing. More detail • Use
session.close()
when you want to terminate the session right away and you don’t need to wait for pending tasks to finish. • Use
session.shutdown()
when you want a graceful shutdown that allows the session to finish or drain any in-flight work before it fully stops. If you’d like, tell me which SDK (Python or agents-js) and I can provide a short code example showing the recommended pattern for each method.
n
agents-js. Why shutdown closes the room after finishing but close() leaves the room open if both are in the session?
t
Thanks — I’m responding to your question about why, in agents-js, calling
session.shutdown()
closes the room after finishing while
session.close()
leaves the room open when both are used. Short answer • I can’t confirm a documented, implementation-level reason for the exact difference in agents-js from the sources I have. The documentation shows that
shutdown()
is intended for a graceful shutdown (draining/finishing in-flight work) and that `close()`/`aclose()` are immediate closes in other SDKs, but it does not explicitly state that
shutdown()
will remove the room while
close()
will not in agents-js. What we do know from the docs •
shutdown()
is described as a graceful, non-blocking shutdown that can allow pending work to finish. •
close()
in other SDKs (and
aclose()
in Python) performs an immediate close/disconnect. • The Node.js naming convention uses
close()
rather than `aclose()`; JavaScript async methods typically return a Promise and are awaited rather than using an
a
prefix. Why you might observe the behavior you described (possible explanations) • A graceful shutdown can finish tasks or signal room cleanup logic that only runs once pending work completes; that could trigger room-close logic if the agent was the last active participant. • An immediate
close()
may disconnect the agent without running the same draining/cleanup flow, leaving the room alive for other participants or for explicit teardown steps. Next steps so I can help precisely • Could you confirm the SDK version of agents-js you’re using and paste the small snippet showing how you call
shutdown()
and
close()
? (A brief example is enough.) • Do you see any log messages when
shutdown()
runs that indicate cleanup or “room closed” events? • Are there other participants in the room when you call
close()
versus
shutdown()
? With that info I can: • Show a recommended pattern to ensure the room is closed when you want it to be closed. • Suggest a minimal reproduction you can run locally to verify whether the observed difference is deterministic or tied to timing. • If necessary, point to the exact code path or sample that demonstrates the lifecycle behavior once I have the version/snippet. Sources: Job lifecycle | LiveKit Documentation | Agent session | LiveKit Documentation