Skip to content

fix a validation error when sending request to openai with name parameter #88

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

Merged
merged 4 commits into from
Mar 31, 2025

Conversation

boxbag
Copy link
Contributor

@boxbag boxbag commented Mar 30, 2025

Fixes an error when running the workflow_orchestrator_worker example in mode=iterative. Encountered the error below:

{
  "data": {
    "request": {
      "method": "POST",
      "url": {
        "_uri_reference": [
          "https",
          "",
          "api.openai.com",
          null,
          "/v1/chat/completions",
          null,
          null
        ]
      },
      "headers": [
        "host",
        "accept-encoding",
        "connection",
        "accept",
        "content-type",
        "user-agent",
        "x-stainless-lang",
        "x-stainless-package-version",
        "x-stainless-os",
        "x-stainless-arch",
        "x-stainless-runtime",
        "x-stainless-runtime-version",
        "authorization",
        "x-stainless-async",
        "x-stainless-retry-count",
        "content-length"
      ],
      "extensions": {
        "timeout": {
          "connect": 5.0,
          "read": 600.0,
          "write": "600.0",
          "pool": "600.0"
        }
      },
      "stream": [
        {
          "capitalize": "<callable: capitalize>",
          "center": "<callable: center>",
          "count": "<callable: count>",
          "decode": "<callable: decode>",
          "endswith": "<callable: endswith>",
          "expandtabs": "<callable: expandtabs>",
          "find": "<callable: find>",
          "fromhex": "<callable: fromhex>",
          "hex": "<callable: hex>",
          "index": "<callable: index>",
          "isalnum": "<callable: isalnum>",
          "isalpha": "<callable: isalpha>",
          "isascii": "<callable: isascii>",
          "isdigit": "<callable: isdigit>",
          "islower": "<callable: islower>",
          "isspace": "<callable: isspace>",
          "istitle": "<callable: istitle>",
          "isupper": "<callable: isupper>",
          "join": "<callable: join>",
          "ljust": "<callable: ljust>",
          "lower": "<callable: lower>",
          "lstrip": "<callable: lstrip>",
          "maketrans": "<callable: maketrans>",
          "partition": "<callable: partition>",
          "removeprefix": "<callable: removeprefix>",
          "removesuffix": "<callable: removesuffix>",
          "replace": "<callable: replace>",
          "rfind": "<callable: rfind>",
          "rindex": "<callable: rindex>",
          "rjust": "<callable: rjust>",
          "rpartition": "<callable: rpartition>",
          "rsplit": "<callable: rsplit>",
          "rstrip": "<callable: rstrip>",
          "split": "<callable: split>",
          "splitlines": "<callable: splitlines>",
          "startswith": "<callable: startswith>",
          "strip": "<callable: strip>",
          "swapcase": "<callable: swapcase>",
          "title": "<callable: title>",
          "translate": "<callable: translate>",
          "upper": "<callable: upper>",
          "zfill": "<callable: zfill>"
        }
      ],
      "_content": "b'{\"messages\":[{\"role\":\"system\",\"content\":\"\\\\n                You are an expert planner. Given an objective task and a list of MCP servers (which are collections of
tools)\\\\n                or Agents (which are collections of servers), your job is to break down the objective into a series of steps,\\\\n                which can be performed by LLMs with access to
the servers or agents.\\\\n                \"},{\"role\":\"system\",\"content\":\"\\\\n                You are an expert planner. Given an objective task and a list of MCP servers (which are collections
of tools)\\\\n                or Agents (which are collections of servers), your job is to break down the objective into a series of steps,\\\\n                which can be performed by LLMs with access
to the servers or agents.\\\\n                \"},{\"role\":\"user\",\"content\":\"You are tasked with determining only the next step in a plan\\\\nneeded to complete an objective. You must analyze the
current state and progress from previous steps \\\\nto decide what to do next.\\\\n\\\\nA Step must be sequential in the plan, but can have independent parallel subtasks. Only return a single
Step.\\\\n\\\\nObjective: Load the student\\'s short story, \\\\n        and generate a report with feedback across proofreading, \\\\n        factuality/logical consistency and style adherence. Use the
style rules from \\\\n        https://apastyle.apa.org/learn/quick-guide-on-formatting and \\\\n        https://apastyle.apa.org/learn/quick-guide-on-references.\\\\n        Write the graded report to the
same directory as the short story\\\\n\\\\nPlan Objective: Load the student\\'s short story, \\\\n        and generate a report with feedback across proofreading, \\\\n        factuality/logical
consistency and style adherence. Use the style rules from \\\\n        https://apastyle.apa.org/learn/quick-guide-on-formatting and \\\\n
https://apastyle.apa.org/learn/quick-guide-on-references.\\\\n        Write the graded report to the same directory as the short story\\\\n\\\\nProgress So Far (steps completed):\\\\nNo steps executed
yet\\\\n\\\\nPlan Current Status: In Progress\\\\nPlan Current Result: In Progress\\\\n    \\\\nIf the previous results achieve the objective, return is_complete=True.\\\\nOtherwise, generate the next
Step.\\\\n\\\\nYou have access to the following MCP Servers (which are collections of tools/functions),\\\\nand Agents (which are collections of servers):\\\\n\\\\nAgents:\\\\n1. Agent Name:
finder\\\\nDescription: You are an agent with access to the filesystem, \\\\n            as well as the ability to fetch URLs. Your job is to identify \\\\n            the closest match to a user\\'s
request, make the appropriate tool calls, \\\\n            and return the URI and CONTENTS of the closest match.\\\\nServers in Agent: - Server Name: fetch\\\\n- Server Name: filesystem\\\\n2. Agent Name:
writer\\\\nDescription: You are an agent that can write to the filesystem.\\\\n            You are tasked with taking the user\\'s input, addressing it, and \\\\n            writing the result to disk in
the appropriate location.\\\\nServers in Agent: - Server Name: filesystem\\\\n3. Agent Name: proofreader\\\\nDescription: \\\\\"Review the short story for grammar, spelling, and punctuation errors.\\\\n
Identify any awkward phrasing or structural issues that could improve clarity. \\\\n            Provide detailed feedback on corrections.\\\\nServers in Agent: - Server Name: fetch\\\\n4. Agent Name:
fact_checker\\\\nDescription: Verify the factual consistency within the story. Identify any contradictions,\\\\n            logical inconsistencies, or inaccuracies in the plot, character actions, or
setting. \\\\n            Highlight potential issues with reasoning or coherence.\\\\nServers in Agent: - Server Name: fetch\\\\n5. Agent Name: style_enforcer\\\\nDescription: Analyze the story for
adherence to style guidelines.\\\\n            Evaluate the narrative flow, clarity of expression, and tone. Suggest improvements to \\\\n            enhance storytelling, readability, and
engagement.\\\\nServers in Agent: - Server Name: fetch\\\\n\\\\nGenerate the next step, by specifying a description of the step and independent subtasks that can run in parallel:\\\\nFor each subtask
specify:\\\\n    1. Clear description of the task that an LLM can execute  \\\\n    2. Name of 1 Agent OR List of MCP server names to use for the task\\\\n\\\\nReturn your response in the following JSON
structure:\\\\n    {\\\\n    \\\\n        \\\\\"description\\\\\": \\\\\"Description of step 1\\\\\",\\\\n        \\\\\"tasks\\\\\": [\\\\n            {\\\\n                \\\\\"description\\\\\":
\\\\\"Description of task 1\\\\\",\\\\n                \\\\\"agent\\\\\": \\\\\"agent_name\\\\\"  # For AgentTask\\\\n            }\\\\n        ],\\\\n        \\\\\"is_complete\\\\\": false\\\\n
}\\\\n\\\\nYou must respond with valid JSON only, with no triple backticks. No markdown formatting.\\\\nNo extra text. Do not wrap in 
json code fences.\"},{\"role\":\"assistant\",\"content\":\"{\\\\n
\\\\\"description\\\\\": \\\\\"Load the student\\'s short story from the filesystem by using the finder agent to locate the file and retrieve its contents. This step sets the foundation by ensuring we
have the text and its directory information for the subsequent report generation.\\\\\",\\\\n    \\\\\"tasks\\\\\": [\\\\n        {\\\\n            \\\\\"description\\\\\": \\\\\"Invoke the finder agent
to access the filesystem, locate the student\\'s short story file, and load its content.\\\\\",\\\\n            \\\\\"agent\\\\\": \\\\\"finder\\\\\"\\\\n        }\\\\n    ],\\\\n
\\\\\"is_complete\\\\\": false\\\\n}\",\"tool_calls\":null,\"audio\":null,\"refusal\":null,\"name\":\"LLM Orchestration Planner\"},{\"role\":\"user\",\"content\":\"You are tasked with determining only the
next step in a plan\\\\nneeded to complete an objective. You must analyze the current state and progress from previous steps \\\\nto decide what to do next.\\\\n\\\\nA Step must be sequential in the plan,
but can have independent parallel subtasks. Only return a single Step.\\\\n\\\\nObjective: Load the student\\'s short story, \\\\n        and generate a report with feedback across proofreading, \\\\n
factuality/logical consistency and style adherence. Use the style rules from \\\\n        https://apastyle.apa.org/learn/quick-guide-on-formatting and \\\\n
https://apastyle.apa.org/learn/quick-guide-on-references.\\\\n        Write the graded report to the same directory as the short story\\\\n\\\\nPlan Objective: Load the student\\'s short story, \\\\n
and generate a report with feedback across proofreading, \\\\n        factuality/logical consistency and style adherence. Use the style rules from \\\\n
https://apastyle.apa.org/learn/quick-guide-on-formatting and \\\\n        https://apastyle.apa.org/learn/quick-guide-on-references.\\\\n        Write the graded report to the same directory as the short
story\\\\n\\\\nProgress So Far (steps completed):\\\\n1:\\\\nStep: Load the student\\'s short story from the filesystem by using the finder agent to locate the file and retrieve its contents. This step
sets the foundation by ensuring we have the text and its directory information for the subsequent report generation.\\\\nStep Subtasks:\\\\n  - Task: Invoke the finder agent to access the filesystem,
locate the student\\'s short story file, and load its content.\\\\nResult: The file \\\\\"file_1.md\\\\\" appears to be the student\\'s short story. Its content is as
follows:\\\\n\\\\n--------------------------------------------------\\\\n## The Battle of Glimmerwood\\\\n\\\\nIn the heart of Glimmerwood, a mystical forest knowed for its radiant trees, a small village
thrived.\\\\nThe villagers, who were live peacefully, shared their home with the forest\\'s magical creatures,\\\\nespecially the Glimmerfoxes whose fur shimmer like moonlight.\\\\n\\\\nOne fateful
evening, the peace was shaterred when the infamous Dark Marauders attack.\\\\nLead by the cunning Captain Thorn, the bandits aim to steal the precious Glimmerstones which was believed to grant
immortality.\\\\n\\\\nAmidst the choas, a young girl named Elara stood her ground, she rallied the villagers and devised a clever plan.\\\\nUsing the forests natural defenses they lured the marauders into
a trap.\\\\nAs the bandits aproached the village square, a herd of Glimmerfoxes emerged, blinding them with their dazzling light,\\\\nthe villagers seized the opportunity to captured the
invaders.\\\\n\\\\nElara\\'s bravery was celebrated and she was hailed as the \\\\\"Guardian of Glimmerwood\\\\\".\\\\nThe Glimmerstones were secured in a hidden grove protected by an ancient
spell.\\\\n\\\\nHowever, not all was as it seemed. The Glimmerstones true power was never confirm,\\\\nand whispers of a hidden agenda linger among the
villagers.\\\\n--------------------------------------------------\\\\n\\\\nNow that we have loaded the student\\'s short story, the next step in the workflow can be executed.\\\\n\\\\nPlan Current Status:
In Progress\\\\nPlan Current Result: In Progress\\\\n    \\\\nIf the previous results achieve the objective, return is_complete=True.\\\\nOtherwise, generate the next Step.\\\\n\\\\nYou have access to the
following MCP Servers (which are collections of tools/functions),\\\\nand Agents (which are collections of servers):\\\\n\\\\nAgents:\\\\n1. Agent Name: finder\\\\nDescription: You are an agent with
access to the filesystem, \\\\n            as well as the ability to fetch URLs. Your job is to identify \\\\n            the closest match to a user\\'s request, make the appropriate tool calls, \\\\n
and return the URI and CONTENTS of the closest match.\\\\nServers in Agent: - Server Name: fetch\\\\n- Server Name: filesystem\\\\n2. Agent Name: writer\\\\nDescription: You are an agent that can write to
the filesystem.\\\\n            You are tasked with taking the user\\'s input, addressing it, and \\\\n            writing the result to disk in the appropriate location.\\\\nServers in Agent: - Server
Name: filesystem\\\\n3. Agent Name: proofreader\\\\nDescription: \\\\\"Review the short story for grammar, spelling, and punctuation errors.\\\\n            Identify any awkward phrasing or structural
issues that could improve clarity. \\\\n            Provide detailed feedback on corrections.\\\\nServers in Agent: - Server Name: fetch\\\\n4. Agent Name: fact_checker\\\\nDescription: Verify the factual
consistency within the story. Identify any contradictions,\\\\n            logical inconsistencies, or inaccuracies in the plot, character actions, or setting. \\\\n            Highlight potential issues
with reasoning or coherence.\\\\nServers in Agent: - Server Name: fetch\\\\n5. Agent Name: style_enforcer\\\\nDescription: Analyze the story for adherence to style guidelines.\\\\n            Evaluate the
narrative flow, clarity of expression, and tone. Suggest improvements to \\\\n            enhance storytelling, readability, and engagement.\\\\nServers in Agent: - Server Name: fetch\\\\n\\\\nGenerate
the next step, by specifying a description of the step and independent subtasks that can run in parallel:\\\\nFor each subtask specify:\\\\n    1. Clear description of the task that an LLM can execute
\\\\n    2. Name of 1 Agent OR List of MCP server names to use for the task\\\\n\\\\nReturn your response in the following JSON structure:\\\\n    {\\\\n    \\\\n        \\\\\"description\\\\\":
\\\\\"Description of step 1\\\\\",\\\\n        \\\\\"tasks\\\\\": [\\\\n            {\\\\n                \\\\\"description\\\\\": \\\\\"Description of task 1\\\\\",\\\\n                \\\\\"agent\\\\\":
\\\\\"agent_name\\\\\"  # For AgentTask\\\\n            }\\\\n        ],\\\\n        \\\\\"is_complete\\\\\": false\\\\n    }\\\\n\\\\nYou must respond with valid JSON only, with no triple backticks. No
markdown formatting.\\\\nNo extra text. Do not wrap in
json code
fences.\"}],\"model\":\"o3-mini\",\"max_completion_tokens\":4096,\"reasoning_effort\":\"high\",\"stop\":null,\"tools\":[{\"type\":\"function\",\"function\":{\"name\":\"__human_input__\",\"description\":\"
\\\\n        Request input from a human user. Pauses the workflow until input is received.\\\\n\\\\n        Args:\\\\n            request: The human input request\\\\n\\\\n        Returns:\\\\n
The input provided by the human\\\\n\\\\n        Raises:\\\\n            TimeoutError: If the timeout is exceeded\\\\n
\",\"parameters\":{\"$defs\":{\"HumanInputRequest\":{\"description\":\"Represents a request for human
input.\",\"properties\":{\"prompt\":{\"title\":\"Prompt\",\"type\":\"string\"},\"description\":{\"anyOf\":[{\"type\":\"string\"},{\"type\":\"null\"}],\"default\":null,\"title\":\"Description\"},\"request_
id\":{\"anyOf\":[{\"type\":\"string\"},{\"type\":\"null\"}],\"default\":null,\"title\":\"Request
Id\"},\"workflow_id\":{\"anyOf\":[{\"type\":\"string\"},{\"type\":\"null\"}],\"default\":null,\"title\":\"Workflow
Id\"},\"timeout_seconds\":{\"anyOf\":[{\"type\":\"integer\"},{\"type\":\"null\"}],\"default\":null,\"title\":\"Timeout
Seconds\"},\"metadata\":{\"anyOf\":[{\"type\":\"object\"},{\"type\":\"null\"}],\"default\":null,\"title\":\"Metadata\"}},\"required\":[\"prompt\"],\"title\":\"HumanInputRequest\",\"type\":\"object\"}},\"p
roperties\":{\"request\":{\"$ref\":\"#/$defs/HumanInputRequest\"}},\"required\":[\"request\"],\"title\":\"request_human_inputArguments\",\"type\":\"object\"}}}]}'"
    },
    "message": "Error code: 400 - {'error': {'message': \"Invalid 'messages[3].name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.\", 'type':
'invalid_request_error', 'param': 'messages[3].name', 'code': 'invalid_value'}}",
    "body": {
      "message": "Invalid 'messages[3].name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.",
      "type": "invalid_request_error",
      "param": "messages[3].name",
      "code": "invalid_value"
    },
    "code": "invalid_value",
    "param": "messages[3].name",
    "type": "invalid_request_error",
    "response": "<httpx.Response [400] https://api.openai.com/v1/chat/completions>",
    "status_code": 400,
    "request_id": "req_ffdfb55cd833a075c5ba2d21c47b611f"
  }
}

Copy link
Collaborator

@saqadri saqadri left a comment

Choose a reason for hiding this comment

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

Requesting one change to add a comment, otherwise looks good! Thank you @boxbag for finding an issue and contributing a fix!

Copy link
Collaborator

@saqadri saqadri left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution and fix!

@saqadri saqadri merged commit f8f54f2 into lastmile-ai:main Mar 31, 2025
4 checks passed
@boxbag boxbag deleted the feature/fix-openai-name-validation branch March 31, 2025 19:56
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