Skip to content

Support tool use in Python SDK#122

Merged
ultmaster merged 6 commits intomainfrom
python-sdk-tool
Aug 20, 2025
Merged

Support tool use in Python SDK#122
ultmaster merged 6 commits intomainfrom
python-sdk-tool

Conversation

@ultmaster
Copy link
Contributor

This pull request introduces enhanced support for template expressions and automatic type conversion in schema and runtime parameter handling for the POML language, along with improved Python API support for tool calls and richer content types. The changes improve flexibility, correctness, and interoperability across both the TypeScript and Python implementations, and are accompanied by thorough documentation and test coverage.

Template Expression and Schema Handling Improvements:

  • Added support for template expressions in attributes of <tool-definition> and <output-schema> elements, allowing dynamic generation of tool names, descriptions, and schemas. This is reflected in both the documentation (standalone.md) and the implementation in PomlFile, including the new handleTextAsString helper. [1] [2] [3]
  • The lang attribute of schemas now supports template expressions, enabling dynamic schema language selection.

Runtime Parameter Handling and Type Conversion:

  • Runtime parameter keys are now automatically converted from kebab-case to camelCase, and values are converted to appropriate types (boolean, number, JSON, or string), both in the implementation and in the documentation. [1] [2]
  • Extensive new tests verify correct parsing, conversion, and template handling for runtime parameters, including edge cases and error fallback.

Python API: Tool Call and Rich Content Support:

  • Introduced ContentMultiMediaToolRequest and ContentMultiMediaToolResponse models to represent tool calls and responses in the Python API, and updated the Speaker type to include "tool".
  • Enhanced the OpenAI chat conversion logic to handle tool call and tool response messages, including proper mapping of tool calls and rich content to OpenAI's expected format.
  • Added a new PomlFrame model to encapsulate messages, schemas, tools, and runtime parameters in a single object.
  • Added "message_dict" as a valid output format for the API.

Utility Improvements:

  • Added a getTools() method to ToolsSchema for easier access to all defined tools.

These changes collectively make the POML language and its tooling more expressive, robust, and compatible with modern LLM integration patterns.

Copilot AI review requested due to automatic review settings August 20, 2025 13:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces comprehensive support for tool calls and enhanced template expression handling in the POML language, adding rich API capabilities for Python SDK integration and improved flexibility in schema and runtime parameter management.

Key Changes

  • Enhanced template expression support in <tool-definition> and <output-schema> element attributes with dynamic name, description, and schema generation
  • Automatic runtime parameter key conversion from kebab-case to camelCase with intelligent type conversion (boolean, number, JSON parsing)
  • Python API enrichment with tool call/response models, OpenAI/LangChain format conversion, and new PomlFrame container for complete conversation metadata

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
python/tests/test_poml_formats.py Comprehensive test coverage for new tool call conversions, format handling, and runtime parameter processing
python/poml/api.py Core API enhancements with tool call models, format conversion functions, and expanded output format support
packages/poml/util/schema.ts Added getTools() utility method for accessing all defined tools
packages/poml/tests/file.test.tsx Extensive test coverage for runtime parameter conversion and template expression handling
packages/poml/file.tsx Implementation of template expression support in attributes and runtime parameter conversion logic
docs/language/standalone.md Updated documentation covering template expressions in attributes and runtime parameter conversion rules

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

return langchain_messages


def _camel_case_to_snake_case(name: str) -> str:
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

Missing import for the re module. The function uses re.sub() but re is not imported at the top of the file.

Copilot uses AI. Check for mistakes.
else:
# TODO: Make it a RichContent object
pydantic_result = [PomlMessage(speaker="human", content=result)]
pydantic_messages = [PomlMessage(speaker="human", content=messages_data)] # type: ignore
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The type ignore comment suggests a type mismatch that should be properly handled. Consider either fixing the type conversion or adding a more specific comment explaining why the type ignore is necessary.

Suggested change
pydantic_messages = [PomlMessage(speaker="human", content=messages_data)] # type: ignore
# Ensure content is a string for legacy format
if isinstance(messages_data, list):
content_str = "\n".join(str(item) for item in messages_data)
else:
content_str = str(messages_data)
pydantic_messages = [PomlMessage(speaker="human", content=content_str)]

Copilot uses AI. Check for mistakes.
message["tool_calls"] = tool_calls
elif not text_image_contents:
# If no content and no tool calls, skip this message
pass
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

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

The condition elif not text_image_contents: followed by pass and then an if condition checking the same thing creates unclear control flow. Consider simplifying this logic for better readability.

Suggested change
pass

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster merged commit 5be59a6 into main Aug 20, 2025
7 checks passed
@ultmaster ultmaster deleted the python-sdk-tool branch August 27, 2025 00: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