agent-factory: generate agent auto-retrieve-files-from-a-reposito

This commit is contained in:
2026-04-13 20:02:50 +00:00
parent b273901039
commit ae408876a9

View File

@@ -1,33 +1,35 @@
"""
This module defines a LangGraph node function for retrieving files from a repository.
The function interacts with an LLM to determine the workflow files available in the
specified repository and scope.
"""
async def process(state: dict) -> dict:
"""
This node retrieves files from a repository based on the provided URL and update scope.
It uses an LLM to analyze and extract relevant workflow files from the repository.
Input Schema:
- repository_url: The URL of the repository to retrieve files from.
- update_scope: The scope or context for the update (e.g., branch, directory).
Output Schema:
- workflow_files: A list of workflow file names retrieved from the repository.
"""
from app.agent import llm
from langchain_core.messages import SystemMessage, HumanMessage
try:
# Extract input fields from state
repository_url = state.get("repository_url", "")
update_scope = state.get("update_scope", "")
# Validate inputs
if not repository_url or not update_scope:
raise ValueError("Both 'repository_url' and 'update_scope' must be provided.")
# Prepare messages for the LLM
messages = [
SystemMessage(content="You are an assistant that retrieves workflow files from a repository."),
HumanMessage(content=f"Retrieve workflow files from the repository at {repository_url} within the scope '{update_scope}'.")
SystemMessage(content="You are an expert in repository management and file retrieval."),
HumanMessage(content=f"Retrieve all workflow files from the repository at '{repository_url}' "
f"within the scope '{update_scope}'. Provide the list of file names.")
]
# Invoke the LLM
response = await llm.ainvoke(messages)
workflow_files = response.content.splitlines() # Assuming the response lists files line by line.
# Parse the response and return the output
workflow_files = response.content.splitlines() # Assuming the LLM returns file names as newline-separated text
return {"workflow_files": workflow_files, "phase": "complete"}
except Exception as exc:
return {"error": str(exc), "phase": "failed"}