letta-ai / letta

Letta (formerly MemGPT) is a framework for creating LLM services with memory.
https://letta.com
Apache License 2.0
12.08k stars 1.34k forks source link

fix: fix bug with `POST /v1/agents/messages` route returning empty `LettaMessage` base objects #1966

Closed cpacker closed 6 days ago

cpacker commented 6 days ago

Before:

% curl --request POST \
  --url http://localhost:8283/v1/agents/agent-95e54e09-f18b-4bf8-b795-50d86130456e/messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "messages": [
    {
      "role": "user",
      "text": "hi again"
    }
  ]
}'
{
  "messages":[
    {"id":"message-8c0b79c3-224b-46ac-ac8a-3bf2c8130144","date":"2024-10-31T22:51:35+00:00"},
    {"id":"message-8c0b79c3-224b-46ac-ac8a-3bf2c8130144","date":"2024-10-31T22:51:35+00:00"},
    {"id":"message-a9fccc74-6ada-4d13-ac8f-06f628f7c65c","date":"2024-10-31T22:51:35+00:00"}
  ],
  "usage":{"completion_tokens":53,"prompt_tokens":3106,"total_tokens":3159,"step_count":1}
}

After:

% curl --request POST \
  --url http://localhost:8283/v1/agents/agent-95e54e09-f18b-4bf8-b795-50d86130456e/messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "messages": [
    {
      "role": "user",
      "text": "hi again"
    }
  ]
}'
{
  "messages":[
    {"id":"message-ebb31345-bc00-4480-8a5f-b4d6cf875ec8","date":"2024-10-31T23:23:01+00:00","message_type":"internal_monologue","internal_monologue":"The user just sent another greeting. Replying with a question to facilitate the conversation."},
    {"id":"message-ebb31345-bc00-4480-8a5f-b4d6cf875ec8","date":"2024-10-31T23:23:01+00:00","message_type":"function_call","function_call":{"name":"send_message","arguments":"{\n  \"message\": \"Hi! Anything fun you want to talk about?\"\n}","function_call_id":"call_P4JH1VdVUpP30YIqKFIH8s4S"}},
    {"id":"message-e4456e9d-61ca-4ce0-a878-4a822fc0917c","date":"2024-10-31T23:23:01+00:00","message_type":"function_return","function_return":"None","status":"success","function_call_id":"call_P4JH1VdVUpP30YIqKFIH8s4S"}
  ],
  "usage":{"completion_tokens":48,"prompt_tokens":3251,"total_tokens":3299,"step_count":1}
}

After (with use_assistant_message == true):

% curl --request POST \
  --url http://localhost:8283/v1/agents/agent-95e54e09-f18b-4bf8-b795-50d86130456e/messages \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "messages": [
    {
      "role": "user",
      "text": "hi again"
    }
  ], 
  "use_assistant_message": true
}'
{
  "messages":[
    {"id":"message-5b3f8da3-2329-4945-b7e0-ca76cfa375a4","date":"2024-10-31T23:30:49+00:00","message_type":"internal_monologue","internal_monologue":"The user greeted me again. Responding with a friendly question to engage them in the conversation."},
    {"id":"message-5b3f8da3-2329-4945-b7e0-ca76cfa375a4","date":"2024-10-31T23:30:49+00:00","message_type":"assistant_message","assistant_message":"Hello! What brings you here today?"},
    {"id":"message-bfb392c4-bfc6-4a28-86cc-17125b1d3114","date":"2024-10-31T23:30:49+00:00","message_type":"function_return","function_return":"None","status":"success","function_call_id":"call_j4MWxybVBc7CICOg9lYqmscj"}
  ],
  "usage":{"completion_tokens":48,"prompt_tokens":3391,"total_tokens":3439,"step_count":1}
}