Skip to content

Commit

Permalink
feat: Allow changing the system prompt for each generation
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Dec 21, 2024
1 parent 7baaf02 commit 52985d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libertai_agents/libertai_agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ def get_model_information(self) -> ModelInformation:
)

async def generate_answer(
self, messages: list[Message], only_final_answer: bool = True
self,
messages: list[Message],
only_final_answer: bool = True,
system_prompt: str | None = None,
) -> AsyncIterable[Message]:
"""
Generate an answer based on a conversation
:param messages: List of messages previously sent in this conversation
:param only_final_answer: Only yields the final answer without including the thought process (tool calls and their response)
:param system_prompt: Optional system prompt to customize the agent's behavior. If one was specified in the agent class instanciation, this will override it.
:return: The string response of the agent
"""
if len(messages) == 0:
Expand All @@ -102,7 +106,7 @@ async def generate_answer(

for _ in range(MAX_TOOL_CALLS_DEPTH):
prompt = self.model.generate_prompt(
messages, self.tools, system_prompt=self.system_prompt
messages, self.tools, system_prompt=system_prompt or self.system_prompt
)
async with aiohttp.ClientSession() as session:
response = await self.__call_model(session, prompt)
Expand Down

0 comments on commit 52985d7

Please sign in to comment.