Skip to content
Merged

Dev #147

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions prometheus/lang_graph/graphs/issue_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from prometheus.lang_graph.nodes.issue_classification_subgraph_node import (
IssueClassificationSubgraphNode,
)
from prometheus.lang_graph.nodes.issue_documentation_subgraph_node import (
IssueDocumentationSubgraphNode,
)
from prometheus.lang_graph.nodes.issue_feature_subgraph_node import IssueFeatureSubgraphNode
from prometheus.lang_graph.nodes.issue_question_subgraph_node import IssueQuestionSubgraphNode
from prometheus.lang_graph.nodes.noop_node import NoopNode
Expand Down Expand Up @@ -78,6 +81,15 @@ def __init__(
repository_id=repository_id,
)

# Subgraph node for handling documentation issues
issue_documentation_subgraph_node = IssueDocumentationSubgraphNode(
advanced_model=advanced_model,
base_model=base_model,
kg=kg,
git_repo=git_repo,
repository_id=repository_id,
)

# Create the state graph for the issue handling workflow
workflow = StateGraph(IssueState)
# Add nodes to the workflow
Expand All @@ -86,6 +98,7 @@ def __init__(
workflow.add_node("issue_bug_subgraph_node", issue_bug_subgraph_node)
workflow.add_node("issue_question_subgraph_node", issue_question_subgraph_node)
workflow.add_node("issue_feature_subgraph_node", issue_feature_subgraph_node)
workflow.add_node("issue_documentation_subgraph_node", issue_documentation_subgraph_node)
# Set the entry point for the workflow
workflow.set_entry_point("issue_type_branch_node")
# Define the edges and conditions for the workflow
Expand All @@ -97,7 +110,7 @@ def __init__(
IssueType.AUTO: "issue_classification_subgraph_node",
IssueType.BUG: "issue_bug_subgraph_node",
IssueType.FEATURE: "issue_feature_subgraph_node",
IssueType.DOCUMENTATION: END,
IssueType.DOCUMENTATION: "issue_documentation_subgraph_node",
IssueType.QUESTION: "issue_question_subgraph_node",
},
)
Expand All @@ -108,14 +121,15 @@ def __init__(
{
IssueType.BUG: "issue_bug_subgraph_node",
IssueType.FEATURE: "issue_feature_subgraph_node",
IssueType.DOCUMENTATION: END,
IssueType.DOCUMENTATION: "issue_documentation_subgraph_node",
IssueType.QUESTION: "issue_question_subgraph_node",
},
)
# Add edges for ending the workflow
workflow.add_edge("issue_bug_subgraph_node", END)
workflow.add_edge("issue_question_subgraph_node", END)
workflow.add_edge("issue_feature_subgraph_node", END)
workflow.add_edge("issue_documentation_subgraph_node", END)

self.graph = workflow.compile()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import logging
import threading

from langchain_core.messages import HumanMessage

from prometheus.lang_graph.subgraphs.issue_documentation_state import IssueDocumentationState
from prometheus.utils.issue_util import format_issue_info


class IssueDocumentationAnalyzerMessageNode:
FIRST_HUMAN_PROMPT = """\
I am going to share details about a documentation update request and its related context.
Please analyze this request and provide a detailed plan for updating the documentation:

1. Issue Understanding:
- Analyze the issue title, description, and comments to understand what documentation needs to be updated
- Identify the type of documentation change (new documentation, updates, fixes, improvements)

2. Context Analysis:
- Review the retrieved documentation files and source code context
- Identify which files need to be modified, created, or updated
- Understand the current documentation structure and style

3. Documentation Plan:
- Provide a step-by-step plan for updating the documentation
- Specify which files to create, edit, or delete
- Describe what content needs to be added or changed
- Ensure consistency with existing documentation style
- Include any code examples, API references, or diagrams if needed

Here is the documentation update request:
-- BEGIN ISSUE --
{issue_info}
-- END ISSUE --

Here is the relevant context (existing documentation and source code):
--- BEGIN CONTEXT --
{documentation_context}
--- END CONTEXT --

Based on the above information, please provide a detailed analysis and plan for updating the documentation.
"""

def __init__(self):
self._logger = logging.getLogger(f"thread-{threading.get_ident()}.{__name__}")

def __call__(self, state: IssueDocumentationState):
human_message = self.FIRST_HUMAN_PROMPT.format(
issue_info=format_issue_info(
state["issue_title"], state["issue_body"], state["issue_comments"]
),
documentation_context="\n\n".join(
[str(context) for context in state["documentation_context"]]
),
)
self._logger.debug(f"Sending message to IssueDocumentationAnalyzerNode:\n{human_message}")
return {"issue_documentation_analyzer_messages": [HumanMessage(human_message)]}
71 changes: 71 additions & 0 deletions prometheus/lang_graph/nodes/issue_documentation_analyzer_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import functools
import logging
import threading

from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import SystemMessage
from langchain_core.tools import StructuredTool

from prometheus.lang_graph.subgraphs.issue_documentation_state import IssueDocumentationState
from prometheus.tools.web_search import WebSearchTool


class IssueDocumentationAnalyzerNode:
SYS_PROMPT = """
You are an expert technical writer and software documentation specialist. Your role is to:

1. Carefully analyze documentation update requests by:
- Understanding the issue description and what documentation changes are needed
- Identifying which documentation files need to be created, updated, or modified
- Understanding the context of existing documentation and source code

2. Create a comprehensive documentation plan through systematic analysis:
- Identify specific documentation files that need changes
- Determine what content needs to be added, updated, or removed
- Ensure consistency with existing documentation style and structure
- Consider the target audience and documentation purpose

3. Provide a clear, actionable plan that includes:
- List of files to create, edit, or delete
- Specific content changes for each file
- Code examples, API references, or diagrams if needed
- Recommendations for improving documentation clarity and completeness

Important:
- Keep descriptions precise and actionable
- Follow existing documentation conventions and style
- Ensure technical accuracy
- Only leave your direct final analysis and plan in the last response!

Your analysis should be thorough enough that an editor can implement the changes directly.
"""

def __init__(self, model: BaseChatModel):
self.system_prompt = SystemMessage(self.SYS_PROMPT)
self.web_search_tool = WebSearchTool()
self.tools = self._init_tools()
self.model_with_tools = model.bind_tools(self.tools)

self._logger = logging.getLogger(f"thread-{threading.get_ident()}.{__name__}")

def _init_tools(self):
"""Initializes tools for the node."""
tools = []

web_search_fn = functools.partial(self.web_search_tool.web_search)
web_search_tool = StructuredTool.from_function(
func=web_search_fn,
name=self.web_search_tool.web_search.__name__,
description=self.web_search_tool.web_search_spec.description,
args_schema=self.web_search_tool.web_search_spec.input_schema,
)
tools.append(web_search_tool)

return tools

def __call__(self, state: IssueDocumentationState):
message_history = [self.system_prompt] + state["issue_documentation_analyzer_messages"]
response = self.model_with_tools.invoke(message_history)

self._logger.debug(response)
return {"issue_documentation_analyzer_messages": [response]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import logging
import threading

from prometheus.lang_graph.subgraphs.issue_documentation_state import IssueDocumentationState
from prometheus.utils.issue_util import format_issue_info


class IssueDocumentationContextMessageNode:
DOCUMENTATION_QUERY = """\
{issue_info}

Find all relevant documentation files and source code context needed to update the documentation according to this issue.
Focus on:
1. Existing documentation files (README.md, docs/, etc.)
2. Source code that needs to be documented or referenced
3. Related configuration files or examples
4. Any existing documentation that needs to be updated or extended

Include both documentation files and relevant source code context.
"""

def __init__(self):
self._logger = logging.getLogger(f"thread-{threading.get_ident()}.{__name__}")

def __call__(self, state: IssueDocumentationState):
documentation_query = self.DOCUMENTATION_QUERY.format(
issue_info=format_issue_info(
state["issue_title"], state["issue_body"], state["issue_comments"]
),
)
self._logger.debug(f"Sending query to context provider:\n{documentation_query}")
return {"documentation_query": documentation_query}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import logging
import threading

from langchain_core.messages import HumanMessage

from prometheus.lang_graph.subgraphs.issue_documentation_state import IssueDocumentationState
from prometheus.utils.lang_graph_util import get_last_message_content


class IssueDocumentationEditMessageNode:
EDIT_PROMPT = """\
Based on the following documentation analysis and plan, please implement the documentation changes using the available file operation tools.

Documentation Analysis and Plan:
--- BEGIN PLAN ---
{documentation_plan}
--- END PLAN ---

Context Collected:
--- BEGIN CONTEXT --
{documentation_context}
--- END CONTEXT --

Please proceed to implement the documentation changes:
1. Read existing files first to understand the current state
2. Make precise edits that preserve existing formatting and style
3. Create new files if specified in the plan
4. Verify your changes by reading the files again after editing

Remember:
- Follow the plan provided in the analysis
- Maintain consistency with existing documentation style
- Ensure all edits are precise and accurate
- Do NOT write or run any tests - focus only on documentation updates
"""

def __init__(self):
self._logger = logging.getLogger(f"thread-{threading.get_ident()}.{__name__}")

def __call__(self, state: IssueDocumentationState):
documentation_plan = get_last_message_content(
state["issue_documentation_analyzer_messages"]
)
documentation_context = "\n\n".join(
[str(context) for context in state["documentation_context"]]
)
human_message = self.EDIT_PROMPT.format(
documentation_plan=documentation_plan, documentation_context=documentation_context
)
self._logger.debug(f"Sending message to EditNode:\n{human_message}")
return {"edit_messages": [HumanMessage(human_message)]}
71 changes: 71 additions & 0 deletions prometheus/lang_graph/nodes/issue_documentation_responder_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import logging
import threading

from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import HumanMessage, SystemMessage

from prometheus.lang_graph.subgraphs.issue_documentation_state import IssueDocumentationState
from prometheus.utils.issue_util import format_issue_info


class IssueDocumentationResponderNode:
SYS_PROMPT = """\
You are a technical writer summarizing documentation updates for a GitHub issue.

Your task is to:
1. Review the documentation update request and the analysis/plan that was created
2. Review the patch that was generated
3. Create a clear, professional response explaining what documentation was updated

The response should:
- Summarize what documentation changes were made
- Explain how the changes address the issue request
- Be concise but informative
- Use a professional, helpful tone

Keep the response focused on what was accomplished, not implementation details.
"""

USER_PROMPT = """\
Here is the documentation update request:
-- BEGIN ISSUE --
{issue_info}
-- END ISSUE --

Here is the analysis and plan that was created:
-- BEGIN PLAN --
{documentation_plan}
-- END PLAN --

Here is the patch with the documentation changes:
-- BEGIN PATCH --
{edit_patch}
-- END PATCH --

Please provide a clear, professional response summarizing the documentation updates for this issue.
"""

def __init__(self, model: BaseChatModel):
self.model = model
self._logger = logging.getLogger(f"thread-{threading.get_ident()}.{__name__}")

def __call__(self, state: IssueDocumentationState):
from prometheus.utils.lang_graph_util import get_last_message_content

documentation_plan = get_last_message_content(
state["issue_documentation_analyzer_messages"]
)

user_message = self.USER_PROMPT.format(
issue_info=format_issue_info(
state["issue_title"], state["issue_body"], state["issue_comments"]
),
documentation_plan=documentation_plan,
edit_patch=state.get("edit_patch", "No changes were made."),
)

messages = [SystemMessage(self.SYS_PROMPT), HumanMessage(user_message)]
response = self.model.invoke(messages)

self._logger.info(f"Documentation update response:\n{response.content}")
return {"issue_response": response.content}
Loading