Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use request context when create agent #2055

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions letta/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from letta.errors import LLMError
from letta.helpers import ToolRulesSolver
from letta.interface import AgentInterface
from letta.interface import AgentInterface, RequestContext
from letta.llm_api.helpers import is_context_overflow_error
from letta.llm_api.llm_api_tools import create
from letta.local_llm.utils import num_tokens_from_functions, num_tokens_from_messages
Expand Down Expand Up @@ -532,18 +532,19 @@ def _get_ai_reply(

try:
response = create(
# agent_state=self.agent_state,
llm_config=self.agent_state.llm_config,
messages=message_sequence,
user_id=self.agent_state.user_id,
functions=allowed_functions,
functions_python=self.functions_python,
function_call=function_call,
# hint
first_message=first_message,
# streaming
stream=stream,
stream_interface=self.interface,
RequestContext(
llm_config=self.agent_state.llm_config,
messages=message_sequence,
user_id=self.agent_state.user_id,
functions=allowed_functions,
functions_python=self.functions_python,
function_call=function_call,
# hint
first_message=first_message,
# streaming
stream=stream,
stream_interface=self.interface,
)
)

if len(response.choices) == 0 or response.choices[0] is None:
Expand Down
7 changes: 5 additions & 2 deletions letta/functions/function_sets/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
MESSAGE_CHATGPT_FUNCTION_MODEL,
MESSAGE_CHATGPT_FUNCTION_SYSTEM_MESSAGE,
)
from letta.interface import RequestContext
from letta.llm_api.llm_api_tools import create
from letta.schemas.message import Message
from letta.utils import json_dumps, json_loads
Expand All @@ -31,8 +32,10 @@ def message_chatgpt(self, message: str):
]
# TODO: this will error without an LLMConfig
response = create(
model=MESSAGE_CHATGPT_FUNCTION_MODEL,
messages=message_sequence,
RequestContext(
model=MESSAGE_CHATGPT_FUNCTION_MODEL,
messages=message_sequence,
)
)

reply = response.choices[0].message.content
Expand Down
22 changes: 21 additions & 1 deletion letta/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from abc import ABC, abstractmethod
from typing import List, Optional
from typing import List, Optional, Union

from colorama import Fore, Style, init

Expand All @@ -10,10 +10,30 @@
INNER_THOUGHTS_CLI_SYMBOL,
)
from letta.schemas.message import Message
from letta.streaming_interface import AgentChunkStreamingInterface, AgentRefreshStreamingInterface
from letta.utils import json_loads, printd
from dataclasses import dataclass
from letta.schemas.llm_config import LLMConfig

init(autoreset=True)

@dataclass
class RequestContext:
llm_config: LLMConfig
messages: List[Message]
user_id: Optional[str] = None
functions: Optional[list] = None
functions_python: Optional[dict] = None
function_call: str = "auto"
first_message: bool = False
use_tool_naming: bool = True
stream: bool = False
stream_interface: Optional[Union[AgentRefreshStreamingInterface, AgentChunkStreamingInterface]] = None
max_tokens: Optional[int] = None
model_settings: Optional[dict] = None



# DEBUG = True # puts full message outputs in the terminal
DEBUG = False # only dumps important messages in the terminal

Expand Down
Loading
Loading