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

feat: add logs to response for tool run #2205

Merged
merged 4 commits into from
Dec 10, 2024
Merged

Conversation

carenthomas
Copy link
Collaborator

Please describe the purpose of this pull request.
Expose the stdout and stderr in FunctionReturn object so that it can be rendered in the UI

How to test
poetry run pytest -s -vv tests/test_server.py::test_tool_run

Have you tested this PR?

1
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 578104, tzinfo=datetime.timezone.utc) message_type='function_return' function_return='Ingested message Hello, world!' status='success' function_call_id='null' stdout=[''] stderr=['']
2
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 579356, tzinfo=datetime.timezone.utc) message_type='function_return' function_return='Ingested message Well well well' status='success' function_call_id='null' stdout=[''] stderr=['']
Letta.letta.services.tool_execution_sandbox - ERROR - Executing tool ingest has an unexpected error: ingest() missing 1 required positional argument: 'message'
Letta.letta.services.tool_execution_sandbox - ERROR - Logging out tool ingest auto-generated code for debugging: 

from typing import *
import pickle
import sys
import base64
agent_state = None


def ingest(message: str):
    """
    Ingest a message into the system.

    Args:
        message (str): The message to ingest into the system.

    Returns:
        str: The result of ingesting the message.
    """
    return f"Ingested message {message}"


result_ZQqiequkcFwRwwGQMqkt = {"results": ingest(), "agent_state": agent_state}
result_ZQqiequkcFwRwwGQMqkt = base64.b64encode(pickle.dumps(result_ZQqiequkcFwRwwGQMqkt)).decode('utf-8')
result_ZQqiequkcFwRwwGQMqkt

3
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 580553, tzinfo=datetime.timezone.utc) message_type='function_return' function_return="Error executing tool ingest: ingest() missing 1 required positional argument: 'message'" status='error' function_call_id='null' stdout=[''] stderr=['Traceback (most recent call last):\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/server/server.py", line 1869, in run_tool_from_source\n    sandbox_run_result = ToolExecutionSandbox(tool.name, tool_args_dict, user_id, tool_object=tool).run(agent_state=agent_state)\n                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/services/tool_execution_sandbox.py", line 79, in run\n    result = self.run_local_dir_sandbox(agent_state=agent_state)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/services/tool_execution_sandbox.py", line 139, in run_local_dir_sandbox\n    raise e\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/services/tool_execution_sandbox.py", line 135, in run_local_dir_sandbox\n    return self.run_local_dir_sandbox_runpy(sbx_config, env_vars, temp_file_path, old_stdout, old_stderr)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/services/tool_execution_sandbox.py", line 228, in run_local_dir_sandbox_runpy\n    result = runpy.run_path(temp_file_path, init_globals=env_vars)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File "<frozen runpy>", line 286, in run_path\n  File "<frozen runpy>", line 98, in _run_module_code\n  File "<frozen runpy>", line 88, in _run_code\n  File "https://accionvegana.org/accio/0ITbvNmLiVHa0l2Z6MHc0/Users/caren/letta/letta/services/tool_sandbox_env/tmpw8z73e2g.py", line 21, in <module>\nTypeError: ingest() missing 1 required positional argument: \'message\'\n']
4
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 582157, tzinfo=datetime.timezone.utc) message_type='function_return' function_return='Ingested message Well well well' status='success' function_call_id='null' stdout=["I'm a distractor\n"] stderr=['']
5
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 583233, tzinfo=datetime.timezone.utc) message_type='function_return' function_return='Ingested message Well well well' status='success' function_call_id='null' stdout=["I'm a distractor\n"] stderr=['']
6
id='null' date=datetime.datetime(2024, 12, 10, 0, 15, 10, 584279, tzinfo=datetime.timezone.utc) message_type='function_return' function_return='None' status='success' function_call_id='null' stdout=["I'm a distractor\n"] stderr=['']
PASSED

============================================== warnings summary ===============================================
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/fields.py:826
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/fields.py:826
  /Users/caren/Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/fields.py:826: PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: 'env'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    warn(

../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291
  /Users/caren/Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)

letta/schemas/llm_config.py:51
  /Users/caren/letta/letta/schemas/llm_config.py:51: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    @root_validator(pre=True)

../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:312
../Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:312
  /Users/caren/Library/Caches/pypoetry/virtualenvs/letta-DRP4JjWO-py3.12/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:312: PydanticDeprecatedSince20: `json_encoders` is deprecated. See https://docs.pydantic.dev/2.9/concepts/serialization/#custom-serializers for alternatives. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    warnings.warn(

<frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: Type google._upb._message.MessageMapContainer uses PyType_Spec with a metaclass that has custom tp_new. This is deprecated and will no longer be allowed in Python 3.14.

<frozen importlib._bootstrap>:488
  <frozen importlib._bootstrap>:488: DeprecationWarning: Type google._upb._message.ScalarMapContainer uses PyType_Spec with a metaclass that has custom tp_new. This is deprecated and will no longer be allowed in Python 3.14.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================= 1 passed, 13 warnings in 0.61s ========================================

Related issues or PRs
Please link any related GitHub issues or PRs.

Is your PR over 500 lines of code?
If so, please break up your PR into multiple smaller PRs so that we can review them quickly, or provide justification for its length.

Additional context
Add any other context or screenshots about the PR here.

Copy link
Collaborator

@sarahwooders sarahwooders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I'm pretty sure this will pass in main (Ollama is unrelated and just fails sometimes)

@carenthomas carenthomas merged commit ab1b440 into main Dec 10, 2024
34 checks passed
@sarahwooders sarahwooders deleted the add-logs-for-tools branch December 10, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants