Proposal: I think we need to add a `repositories`...
# proj-sdk
w
Proposal: I think we need to add a
repositories
parameter to the Conversation class If we're calling ourselves a "Coding Agent SDK", git repos should be a first-class feature. We're going to want to work with them in a variety of contexts. And we need some centralized logic for pulling microagents out of the repo. The Conversation could be responsible for cloning the repo into the
/workspace/projects
dir, and loading microagents. The one weird thing is that currently Conversations don't really have a concept of a working directory--but the tools do 🤔
c
How about we just support something like
setup_fn
that relies on some bash execution functionality?
w
I think we should specifically support repositories
it's not just bash--we need to read
.openhands/microagents/
and load those into the AgentContext
If people are going to use us specifically as a coding agent, some functionality around working with git seems table-stakes
c
We already have
bash
file upload/download
endpoints, i'm trying to get these working over
ConversationInterface
although they seems to belongs to system level https://github.com/All-Hands-AI/agent-sdk/pull/510#issuecomment-3343786617
what about just a utility function:
Copy code
conversation = Conversation(agent=agent, host=xyz)
setup_git_repo(conversation, repo=XXX)
conversation.send_message("hi checkout repo")
conversation.run()
and inside that utility function, we just do smth like:
Copy code
conversation.execute_bash("git clone XXX")
w
why not
conversation.setup_git_repo
?
c
I think we want to make the set of methods for Conversation as generic / simple as possible. I can foresee
setup_git_repo
becomes more and more complex if you have more types of repo to support (eg gh gitlab, with authentication, with different setup, etc), and i don't want that to happen in
Conversation
class
that does feels a bit outside of the domain of agent SDK to me - agent SDK should providing these primitive operations that allow us to do this, but probably not do this for us
w
I agree, it feels a little uncomfortable
I definitely don't want any specific github/gitlab/bitbucket code
But if we're going to say this is a coding agent SDK, I think we need to make repositories a first-class object
Right now I think both Tim and I are implementing the same logic for cloning repos and loading microagents
This is the sort of thing any SDK client is going to need, if they're working on coding use cases
c
I do agree we need these in the SDK library, I just don’t want them to be a part of the Conversation interface though. Conversation interface supposed to be very minimal and robust (ie mirroring our agent server API) Things like repo clone should be one abstraction layer higher than these basic interface operations — they are tasks that can be done with only conversation’s public methods. Therefore I think it is just easier to maintain to keep them as a function outside Conversation, that takes Conversation as an argument (or they can be a mixin). My main worry is that it will turn Conversation into our V0 runtime class that gets polluted with all sorts of microagent loading logic
Another benefit is that, we can create a library of useful functions like “clone repo” “load micro agents” that end user to choose to plug and play, and potentially contribute
w
The issue is that I do think this logic needs to be replicated both locally and remotely
I need to be able to call
clone_repo
and have it run wherever the conversation is running
I don't think it belongs in any kind of contrib/mixin/plugin space--this seems like a basic expectation for coding agents
I share your concerns though
Conversation should ideally just be about the agent loop
Maybe some kind of ConversationContext
it'd be nice to keep track of a single working directory too, instead of passing the same directory over and over again to different tools, and then putting that directory in the system prompts. Seems like a related issue
Maybe we just need a Sandbox object in the SDK
even if it's a separate package, like
openhands/sandbox
but there's some set of expectations here, like • Each Conversation has a working_dir ◦ all the agent tools respect that working dir ◦ we can clone a repo into that working dir ◦ we can run commands against that working dir ◦ the contents of that working_dir can modify agent behavior ▪︎ e.g. via AGENTS.md or microagents
at the very least we might need a local interface for these operations
c
Repositories (and local git operations) would make sense to me, to be first class in agent-sdk. I do have a couple of quick questions though, sorry to interject.
If we're calling ourselves a "Coding Agent SDK", git repos should be a first-class feature. We're going to want to work with them in a variety of contexts. And we need some centralized logic for pulling microagents out of the repo.
Is it possible to have a concept of repos, but: - without a concept of user/org/perms - without ... github tokens? This
I need to be able to call
clone_repo
and have it run wherever the conversation is running
seems like the answer is "no" at least to the second, it's not only public repos, right?
If it's the agent working with repos, then the logic is part of its tools, and we already give it custom secrets, I think.
w
Yes I think we need to completely avoid any concept of auth or specific git providers
nod 1
You should just give it a git URL, maybe with a token plumbed in, like
https://ghp_234@github.com/my/repo
and a branch
c
Correct me if I get this wrong, does that mean like: • agent-sdk does some/many git operations, regardless whether they communicate outside • it may have /api/clone_repo • clients (e.g. app servers) implement the user/org from git provider parts of microagent loading, • but use the sdk for low-level git operations like git clone?
w
That's kind of what I'm thinking. I suppose you could pass multiple repos, including $ORG/.openhands, which would cause the org-level microagents to load
c
at the very least we might need a local interface for these operations
this is exactly what i'm proposing in this comment here though https://github.com/All-Hands-AI/agent-sdk/pull/510#issuecomment-3343786617
The issue is that I do think this logic needs to be replicated both locally and remotely
if a function
clone_git_repo
takes in a
BaseConversation
which can either be Local or Remote -- why do we need to attach
clone_git_repo
as a method of
BaseConversation
to be able to do that though
w
ahh OK yeah I see what you're saying
That does make sense
I don't love the aesthetics of having floating methods like
clone_git_repo
but I think logistically this makes sense
there's also the question of
clone
loading microagents, which needs to modify the AgentContext
c
I don't love the aesthetics of having floating methods like
clone_git_repo
but I think logistically this makes sense
I think we can put these to a separate mixin though, so you can still do
conv.clone_git_repo
but have it not been the part of core methods
> there's also the question of
clone
loading microagents, which needs to modify the AgentContext 🤔 yeah.. this seems will break our assumption that
Agent
should be immutable..
w
yeah currently (in v0) the process goes like: • start runtime • clone repo • grab microagents • initialize agent • start convo which makes sense
In v1, we don't have a concept of runtimes, so that's just assumed to exist
What if we created something like a Workspace, which sits higher-level than the other things
We could have LocalWorkspace, DockerWorkspace, or KubernetesWorkspace
that could have
clone_repo
and
gather_microagents
and then you have
workspace.start_converastion(Conversation())
or something
or
Conversation(workspace=workspace, agent=agent)
and maybe
workspace
would decide if it's local or remote
c
Interesting.. I was trying to solve a somewhat related issue (e.g., right now it is really messy to pass
working_dir
and
persistence_dir
to different tools - since
Conversation
doesn't set the `working_dir`/
persistence_dir
. and we have no single source-of-truth on these from the client side. On agent server side, we even have a global variable for conversation
working_dir
and
persistence_dir
. Got a PR here, my tentative plan was to add
working_dir
and
persistence_dir
to the
ConversationState
and pass it to the tool initializers & server. CC @straight-sundown-84319: I would love to hear your thoughts here, as this will likely mean we will remove the global configuration for
working_dir
and
persistence_dir
. It seems to me that `working_dir`/`persistence_dir` should be configurable at the conversation level rather than one level above (e.g., we might want conversation A to look at the X folder, while conversation B looks at the Y folder, and they should not interfere with each other). In our current setting, our conversation doesn't really start until you hit
conversation.run()
, so i think having each conversation maintain its own
Workspace
is probably a better idea? e.g., we just pass
c=Conversation(working_dir=XX, persistence_dir=YY)
and we make
.workspace
to be an attribute of
Conversation
similar to
.state
?
We could have LocalWorkspace, DockerWorkspace, or KubernetesWorkspace
this kinda makes me feel that "Runtime" class from V0 is backed again lolsob
c
Related to this, in V1, the agent-server has • a workspace_path • multiple conversations In V0, conversation can start in its own runtime -> sandbox, separated from the other In V1, I'm not sure?
c
👆 yeah @calm-artist-7206, this is exactly what i was trying to solve in #531! If we do support configuring working_dir and persistence_dir at conversation-level, we should have the same level of flexibility here
nod 2
c
so i think having each conversation maintain its own
Workspace
is probably a better idea
This sounds right to me...
c
For context, @quick-window-91705 was complaining about the workspace too in a DM to me: >> https://github.com/All-Hands-AI/agent-sdk/pull/517 - I can't resume conversations in CLI for two reasons > 1. the condenser llm wasn't being reconciled > 2. the tools working dir may have changed >> i'm less sure about the tools one, because maybe we don't want to let users resume conversations from a different root dir (the agent may be thoroughly confused) > > but also if they rename the dir and restart the conversation it would be broken, so I'm thinking maybe we allow this and modify the agent context in CLI on restart (letting the agent know the conversation is being resumed, files may have been moved etc) > [11:43 AM] also added a test so that in the future we'll catch reconciliation problems early > [11:44 AM] the PR isn't cleaned up but lmk abt the functional requirements (edited) So I think maybe we can just set workspace_dir and persistence_dir at the conversation level, if@straight-sundown-84319 also think this is a good idea!
c
I wonder a bit here, does the same really apply to
persistence_dir
, Xingyao? Locally, that one seems different: there has to be a place (a filestore) where we can find conversations, and we may load one; that's known at runtime (or maybe it's partially recomputed, but achievable), so we can also save events as they come? (Sorry, just reading the links)
Is it possible that for the cloud, the
persistence dir
changes, for the same conversation, including after it stopped/paused, or was restored?
Also left a comment on the PR. It seems that if persistence dir is per conversation, it needs to contain the
conversation_id
, maybe it can't be the location for all of them
c
Is it possible that for the cloud, the
persistence dir
changes, for the same conversation, including after it stopped/paused, or was restored?
In the cloud, i believe we have nested runtime and just store all conversation events under
/workspace
which is mounted as a persistent volume. At resume time, we simply restore
/workspace
. So i think this pattern will still work there
c
Aha, right, that makes sense actually. So it's fully "local" inside the sandbox, as we were talking before; if it can be restored, then it can be restored fully, and if it can't, well, something went really bad 🤔 That should make things easier
nod 1
c
The only thing that's preventing me from doing so would be this logic in the agent server. @straight-sundown-84319 would love to quickly chat tomorrow to hear your thoughts about this & see if there's any way we can get around this...
s
Let's meet up early
👍 1
c
I guess the other alternative would be, we only allow setting
persistence_dir
for
LocalConversation
and keep this logic in server side unchanged. i think it does make sense to have server manage these metadata by itself. Will poke on the PR and hopefully we have smth to discuss tmr
as long as we have the same
.state.persistence_dir
and
.state.working_dir
interface -- it will unblock other stuff i'm trying to do here
c
If I understood Tim's presentation on Friday correctly a Sandbox was was somewhat decoupled from the Conversation such that in v1 we can re-use the same Sandbox across multiple Conversations over time. Am I understanding correctly that this also extends to the workspace since it is managed within the Sandbox?
w
persistence_dir
and
working_dir
seem like very different things to me... Just to check my knowledge: • persistence dir is where we store e.g. conversation state • working dir is where the agent does its work is that right?
nod 1
if that's the case, I'd expect
persistence_dir
to be set process-wide
ans
working_dir
to be set per-conversation
> > We could have LocalWorkspace, DockerWorkspace, or KubernetesWorkspace > this kinda makes me feel that "Runtime" class from V0 is backed again lolsob I hate to break it to you but we do still need these concepts 🙂 They probably don't go in
openhands/sdk
but they're critically important and probably do belong in the OpenHands/agent-sdk repo
c
@straight-sundown-84319 this is the PR i'd like to discuss 🙂 We can also skip the discussion if these changes (mainly on the server side) sounds good to you https://github.com/All-Hands-AI/agent-sdk/pull/531
> if that's the case, I'd expect
persistence_dir
to be set process-wide > ans
working_dir
to be set per-conversation Yep, this is basically the approach i'm taking now in the PR above