Skip to content

Commit c054cda

Browse files
authored
Getting MalformedMessageError from aviary (#23)
1 parent 5d88e93 commit c054cda

File tree

6 files changed

+177
-186
lines changed

6 files changed

+177
-186
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ repos:
7171
- id: mypy
7272
additional_dependencies:
7373
- fastapi>=0.109 # Match pyproject.toml
74-
- fhaviary
74+
- fhaviary>=0.6 # Match pyproject.toml
7575
- httpx
7676
- litellm>=1.40.9,<=1.40.12 # Match pyproject.toml
7777
- numpy

ldp/agent/react_agent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from typing import Any, Self, cast
33

4-
from aviary.message import Message
4+
from aviary.message import MalformedMessageError, Message
55
from aviary.tools import Tool, ToolRequestMessage, ToolResponseMessage
66
from pydantic import BaseModel, ConfigDict, Field
77
from tenacity import (
@@ -16,7 +16,6 @@
1616
from ldp.graph.modules.react import (
1717
ACT_DEFAULT_PROMPT_TEMPLATE,
1818
REACT_DEFAULT_PROMPT_TEMPLATE,
19-
MalformedMessageError,
2019
ReActModule,
2120
ToolDescriptionMethods,
2221
)

ldp/graph/modules/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from .llm_call import ParsedLLMCallModule
88
from .react import (
9-
MalformedMessageError,
109
ReActModule,
1110
ToolDescriptionMethods,
1211
parse_message,
@@ -15,7 +14,6 @@
1514
from .thought import ThoughtModule
1615

1716
__all__ = [
18-
"MalformedMessageError",
1917
"ParsedLLMCallModule",
2018
"ReActModule",
2119
"ReflectModule",

ldp/graph/modules/react.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import ast
2-
import logging
32
import re
43
import textwrap
54
from collections.abc import Iterable
65
from enum import StrEnum
76
from typing import Any
87

9-
from aviary.message import Message
8+
from aviary.message import EMPTY_CONTENT_BASE_MSG, MalformedMessageError, Message
109
from aviary.tools import Tool, ToolCall, ToolRequestMessage
1110

1211
from ldp.graph.common_ops import FxnOp, PromptOp
@@ -59,25 +58,6 @@
5958
)
6059

6160

62-
class MalformedMessageError(ValueError):
63-
"""Error to throw if some aspect of a ToolRequestMessage is malformed."""
64-
65-
@classmethod
66-
def react_parser_log_filter(cls, record: logging.LogRecord) -> bool:
67-
"""
68-
Filter out common parsing failures not worth looking into from logs.
69-
70-
Returns:
71-
False if the LogRecord should be filtered out, otherwise True to keep it.
72-
"""
73-
# NOTE: match both this Exception type's name and its content, to be robust
74-
return not all(x in record.msg for x in (cls.__name__, EMPTY_CONTENT_BASE_MSG))
75-
76-
77-
# Define separately so we can filter out this message type
78-
EMPTY_CONTENT_BASE_MSG = "No content in message"
79-
80-
8161
def parse_message(m: Message, tools: list[Tool]) -> ToolRequestMessage: # noqa: C901
8262
"""
8363
Parse an Act or ReAct Message into a ToolRequestMessage.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
dependencies = [
1818
"aiofiles",
1919
"dm-tree",
20-
"fhaviary",
20+
"fhaviary>=0.6", # For MalformedMessageError
2121
"httpx",
2222
"litellm",
2323
"networkx[default]~=3.0", # Pin just to keep recent

0 commit comments

Comments
 (0)