mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
[Feat]: add context msg to new conversation endpoint (#8586)
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
@@ -90,6 +90,7 @@ class AgentSession:
|
||||
selected_repository: str | None = None,
|
||||
selected_branch: str | None = None,
|
||||
initial_message: MessageAction | None = None,
|
||||
conversation_instructions: str | None = None,
|
||||
replay_json: str | None = None,
|
||||
) -> None:
|
||||
"""Starts the Agent session
|
||||
@@ -144,6 +145,7 @@ class AgentSession:
|
||||
self.memory = await self._create_memory(
|
||||
selected_repository=selected_repository,
|
||||
repo_directory=repo_directory,
|
||||
conversation_instructions=conversation_instructions,
|
||||
custom_secrets_descriptions=custom_secrets_handler.get_custom_secrets_descriptions()
|
||||
)
|
||||
|
||||
@@ -415,7 +417,11 @@ class AgentSession:
|
||||
return controller
|
||||
|
||||
async def _create_memory(
|
||||
self, selected_repository: str | None, repo_directory: str | None, custom_secrets_descriptions: dict[str, str]
|
||||
self,
|
||||
selected_repository: str | None,
|
||||
repo_directory: str | None,
|
||||
conversation_instructions: str | None,
|
||||
custom_secrets_descriptions: dict[str, str]
|
||||
) -> Memory:
|
||||
memory = Memory(
|
||||
event_stream=self.event_stream,
|
||||
@@ -426,6 +432,7 @@ class AgentSession:
|
||||
if self.runtime:
|
||||
# sets available hosts and other runtime info
|
||||
memory.set_runtime_info(self.runtime, custom_secrets_descriptions)
|
||||
memory.set_conversation_instructions(conversation_instructions)
|
||||
|
||||
# loads microagents from repo/.openhands/microagents
|
||||
microagents: list[BaseMicroagent] = await call_sync_from_async(
|
||||
@@ -435,7 +442,10 @@ class AgentSession:
|
||||
memory.load_user_workspace_microagents(microagents)
|
||||
|
||||
if selected_repository and repo_directory:
|
||||
memory.set_repository_info(selected_repository, repo_directory)
|
||||
memory.set_repository_info(
|
||||
selected_repository,
|
||||
repo_directory
|
||||
)
|
||||
return memory
|
||||
|
||||
def _maybe_restore_state(self) -> State | None:
|
||||
|
||||
@@ -14,6 +14,7 @@ class ConversationInitData(Settings):
|
||||
selected_repository: str | None = Field(default=None)
|
||||
replay_json: str | None = Field(default=None)
|
||||
selected_branch: str | None = Field(default=None)
|
||||
conversation_instructions: str | None = Field(default=None)
|
||||
|
||||
model_config = {
|
||||
'arbitrary_types_allowed': True,
|
||||
|
||||
@@ -155,11 +155,13 @@ class Session:
|
||||
selected_repository = None
|
||||
selected_branch = None
|
||||
custom_secrets = None
|
||||
conversation_instructions = None
|
||||
if isinstance(settings, ConversationInitData):
|
||||
git_provider_tokens = settings.git_provider_tokens
|
||||
selected_repository = settings.selected_repository
|
||||
selected_branch = settings.selected_branch
|
||||
custom_secrets = settings.custom_secrets
|
||||
conversation_instructions = settings.conversation_instructions
|
||||
|
||||
try:
|
||||
await self.agent_session.start(
|
||||
@@ -175,6 +177,7 @@ class Session:
|
||||
selected_repository=selected_repository,
|
||||
selected_branch=selected_branch,
|
||||
initial_message=initial_message,
|
||||
conversation_instructions=conversation_instructions,
|
||||
replay_json=replay_json,
|
||||
)
|
||||
except MicroagentValidationError as e:
|
||||
|
||||
Reference in New Issue
Block a user