So we added a subagent, and because of the description we added
there, there are high chances that Cloud Code will use it whenever it
look up documentation. But we can do better than hoping.
Remember that Cloud MD file? I mentioned that it would be loaded into
every new Cloud Code session, and therefore, we can add
very specific instructions here.
So instead of hoping, we can add this instruction to the Cloud
file. "Whenever working with any third-party
similar, you must look up the official
working with up-to-date information.
Use the Docs Explorer subagent for efficient documentation
lookup." By adding this here, we don't need to add it into
our prompts and we have almost 100% certainty that this
subagent will be used and that Cloud Code will do documentation
So now we can send a prompt like this, and it should
automatically spin up that subagent, that Docs Explorer
subagent to look up the documentation of BetterAuth and so
on. So here it's spinning up the explorer
code base, but also the Docs Explorer, actually multiple instances of the Docs
Explorer, to explore the BetterAuth
documentation and the bun-sql-lite documentation, which is
100% correct for the kind of task I gave it.
Now it's asking for permission to do web search and so on, and yeah, I granted
that. But with that we now have multiple agents
in parallel for efficient work and also for
avoiding a pollution of the main context window.
And that is a great use case for a custom subagent that
makes a lot of sense and how to efficiently use
a subagent. So compared to the last time you now see
it did not perform any research tasks in the main agent, but
instead outsourced all of that to subagents,
main files in the main agent or the important files that were
delivered by the explorer agent in the main agent and
gives me a summary, which of course is the same summary as before, but now
implemented with help of a subagent that will automatically be used now
whenever we work with a third-party library.
At least that's the plan. Now actually here for me in this
project where I just wanted to use this as a demo, this extra review
did find something that must be improved.
This next cookies plugin must be used in this auth.ts
file here because indeed BetterAuth, the authentication library
I want to use here in this demo project, does have
an official Next.js integration guide, and Next.js is the framework
I'm using. And in there it has two main
things you must do. For one, when setting up those API
routes, you must use to_nextjs_handler and that is something
Cloud Code did set up for me here in that file,
but in order to then later properly work with
BetterAuth, we also must add this
next-cookies plugin here to the auth setup and the
auth.ts file. And that indeed is missing here and
was identified by my review here. So I can actually now tell Cloud
Code to fix that next-cookies issue and don't do anything else.
Of course we could also do that manually though.
So if we want to save those tokens, we can also just go
to this BetterAuth setup according to their docs
and add plugins, import next-cookies and call
nextCookies as a function there like this.
That's of course the cheaper way, but we could have also told Cloud Code to
that.