Skip to content

Commit

Permalink
feat: added system prompt override to the CLI (#1602)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacker committed Aug 1, 2024
1 parent 1f0e8fc commit f93e39e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions memgpt/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def run(
persona: Annotated[Optional[str], typer.Option(help="Specify persona")] = None,
agent: Annotated[Optional[str], typer.Option(help="Specify agent name")] = None,
human: Annotated[Optional[str], typer.Option(help="Specify human")] = None,
system: Annotated[Optional[str], typer.Option(help="Specify system prompt (raw text)")] = None,
# model flags
model: Annotated[Optional[str], typer.Option(help="Specify the LLM model")] = None,
model_wrapper: Annotated[Optional[str], typer.Option(help="Specify the LLM model wrapper")] = None,
Expand Down Expand Up @@ -584,6 +585,16 @@ def run(
)
agent_state.llm_config.model_endpoint_type = model_endpoint_type

# NOTE: commented out because this seems dangerous - instead users should use /systemswap when in the CLI
# # user specified a new system prompt
# if system:
# # NOTE: agent_state.system is the ORIGINAL system prompt,
# # whereas agent_state.state["system"] is the LATEST system prompt
# existing_system_prompt = agent_state.state["system"] if "system" in agent_state.state else None
# if existing_system_prompt != system:
# # override
# agent_state.state["system"] = system

# Update the agent with any overrides
ms.update_agent(agent_state)
tools = []
Expand Down Expand Up @@ -638,6 +649,9 @@ def run(
client = create_client()
human_obj = ms.get_human(human, user.id)
persona_obj = ms.get_persona(persona, user.id)
# TODO pull system prompts from the metadata store
# NOTE: will be overriden later to a default
system_prompt = system if system else None
if human_obj is None:
typer.secho("Couldn't find human {human} in database, please run `memgpt add human`", fg=typer.colors.RED)
if persona_obj is None:
Expand All @@ -652,6 +666,7 @@ def run(
# add tools
agent_state = client.create_agent(
name=agent_name,
system_prompt=system_prompt,
embedding_config=embedding_config,
llm_config=llm_config,
memory=memory,
Expand Down
6 changes: 6 additions & 0 deletions memgpt/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def create_agent(
llm_config: Optional[LLMConfig] = None,
# memory
memory: BaseMemory = ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_human_text(DEFAULT_PERSONA)),
# system prompt (can be templated)
system_prompt: Optional[str] = None,
# tools
tools: Optional[List[str]] = None,
include_base_tools: Optional[bool] = True,
Expand Down Expand Up @@ -298,6 +300,7 @@ def create_agent(
"config": {
"name": name,
"preset": preset,
"system": system_prompt,
"persona": memory.memory["persona"].value,
"human": memory.memory["human"].value,
"function_names": tool_names,
Expand Down Expand Up @@ -727,6 +730,8 @@ def create_agent(
llm_config: Optional[LLMConfig] = None,
# memory
memory: BaseMemory = ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_human_text(DEFAULT_PERSONA)),
# system prompt (can be templated)
system_prompt: Optional[str] = None,
# tools
tools: Optional[List[str]] = None,
include_base_tools: Optional[bool] = True,
Expand Down Expand Up @@ -756,6 +761,7 @@ def create_agent(
user_id=self.user_id,
name=name,
memory=memory,
system=system_prompt,
llm_config=llm_config,
embedding_config=embedding_config,
tools=tool_names,
Expand Down

0 comments on commit f93e39e

Please sign in to comment.