Skip to content

feat: Add PromptBasedSGRAgent for models without structured output support#2

Draft
Copilot wants to merge 4 commits into1-feat-prompt-based-schema-definitionfrom
copilot/add-prompt-based-schema-definition
Draft

feat: Add PromptBasedSGRAgent for models without structured output support#2
Copilot wants to merge 4 commits into1-feat-prompt-based-schema-definitionfrom
copilot/add-prompt-based-schema-definition

Conversation

Copy link

Copilot AI commented Nov 17, 2025

SGRAgent uses OpenAI's response_format parameter for schema enforcement, but many models/architectures don't support this. Need alternative using prompt-based schema definition.

Changes

New Agent: PromptBasedSGRAgent

  • Uses XML-tagged JSON in prompts instead of response_format parameter
  • Parses <tool_call>{"name": "...", "arguments": {...}}</tool_call> from LLM responses
  • Injects tool schemas directly into system prompt for better model understanding
  • Maintains same execution flow as SGRAgent (reasoning → action → execution)

Prompt Template

  • sgr_deep_research/core/prompts/prompt_based_system_prompt.txt with XML-style tool calling instructions
  • Includes generated tool schemas with parameter types and descriptions

Core Methods

  • _get_tools_schema(): Generates human-readable tool schemas from Pydantic models
  • _parse_tool_call_from_response(): Regex extraction of JSON from XML tags with validation
  • _prepare_context(): Dynamically builds system prompt with current tool availability

Usage

from sgr_deep_research.core.agents import PromptBasedSGRAgent

agent_def = AgentDefinition(
    name="prompt_based_sgr_agent",
    base_class=PromptBasedSGRAgent,
    # ... rest of config
)

Registered in AgentRegistry as "prompt_based_sgr_agent" for use in configuration files.

Testing

  • 16 new tests covering initialization, schema generation, XML/JSON parsing, and integration
  • All existing agent tests continue to pass
Original prompt

This section details on the original issue you should resolve

<issue_title>feat: prompt based schema definition</issue_title>
<issue_description>The default SGRAgent specifies output schema by setting response_format. But this is not supported for every model and/or architecture. Therefore we need an additional agent implementation that repeats SGRAgent behaviour but ensures output format by explicitly asking for in its prompt.

Excerpt from an example prompt:

...
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
=> The same scheme for tools as we use in SGRAgent
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 17, 2025 18:00
Co-authored-by: ship-dotcom <244338494+ship-dotcom@users.noreply.github.com>
Co-authored-by: ship-dotcom <244338494+ship-dotcom@users.noreply.github.com>
Copilot AI changed the title [WIP] Add prompt-based schema definition for agent implementation feat: Add PromptBasedSGRAgent for models without structured output support Nov 17, 2025
Copilot AI requested a review from ship-dotcom November 17, 2025 18:07
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