Skip to main content

A tool to combine code files into a single prompt

Project description

CodePromptForge ToolKit for Agent Development

Overview

The CodePromptForge ToolKit provides a set of LangChain-compatible tools for developing AI agents that can read, analyze, modify, and write code. These tools enable agents to explore a codebase, extract insights, generate new content, and modify files dynamically.

Features

  • File and Directory Inspection: Retrieve file contents, list directory structures, and analyze project organization.
  • Automated Code Processing: Identify and manipulate specific code files based on extensions.
  • Code Modification: Write and update files programmatically.
  • Cleanup and Maintenance: Remove unnecessary files from results folders.
  • Seamless Integration: Designed to work with LangChain's agent framework.

Available Tools

🔍 1. get_directory_tree

Retrieve the structure of a directory
Returns a list of all files in a specified directory, ignoring files in .gitignore or explicitly excluded.

Usage

tool = GetDirectoryTreeTool()
tool.run(folder_path="src")

Response

["src/main.py", "src/utils/helpers.py", "src/config/settings.json"]

📄 2. get_file_content

Read the content of a specific file
Retrieves the contents of a file for analysis or processing.

Usage

tool = GetFileContentTool()
tool.run(file_path="src/main.py")

Response

"def main():\n    print('Hello, world!')"

📂 3. get_files_in_folder

List all files in a specific folder with their contents
Provides a dictionary where keys are file names and values are their contents.

Usage

tool = GetFilesInFolderTool()
tool.run(folder_path="src")

Response

{
    "main.py": "def main():\n    print('Hello, world!')",
    "config.json": "{'debug': true, 'version': '1.0'}"
}

📁 4. get_files_recursively

Retrieve all files in a folder and its subdirectories
Useful for analyzing an entire project structure.

Usage

tool = GetFilesRecursivelyTool()
tool.run(folder_path="src")

Response

{
    "src/main.py": "def main():\n    print('Hello, world!')",
    "src/utils/helpers.py": "def helper():\n    return 'Helper function'"
}

🔎 5. find_files

Find all files matching specific extensions in the base directory
Helpful for searching for specific types of files, such as Python scripts or Markdown documentation.

Usage

tool = FindFilesTool()
tool.run(extensions=["py", "md"])

Response

["src/main.py", "docs/readme.md"]

✍️ 6. write_file

Write or modify a file
Creates or modifies a file inside the .result folder.

Usage

tool = WriteFileTool()
tool.run(file_path="output.txt", content="New content for the file")

Response

"File written successfully: .result/output.txt"

🧹 7. clean_result_folder

Remove unnecessary files from the .result folder
Ensures that old files don’t clutter the workspace.

Usage

tool = CleanResultFolderTool()
tool.run(excluded_files=["output.txt"])

Response

"Cleaned .result folder. Removed files: ['output.txt']"

🛠 8. forge_prompt

Merge multiple files into a single prompt
Key feature for creating context-rich inputs for LLMs.

Usage

tool = ForgePromptTool()
tool.run(extensions=["py", "md"])

Response

"Merged files: ['src/main.py', 'docs/readme.md']"

🚀 9. run

Runs the forge process on specified file extensions
Automates the process of finding, merging, and generating code prompts.

Usage

tool = RunTool()
tool.run(extensions=["py", "txt"])

Response

"Generated combined prompt in output.txt"

Building AI Agents with the ToolKit

The CodePromptForge ToolKit is designed to be integrated into LangChain agents for intelligent code analysis. Here’s how you can create a React agent that uses these tools:

from langchain.agents import initialize_agent
from langchain.chat_models import ChatOpenAI
from codepromptforge.main import CodePromptForge

# Initialize the CodePromptForge toolkit
forge = CodePromptForge(base_dir=".")

# Create an agent with the tools
agent = initialize_agent(
    tools=forge.get_tools(),
    llm=ChatOpenAI(temperature=0),
    agent="zero-shot-react-description",
    verbose=True
)

# Example: Ask the agent to analyze the project directory
agent.run("List all Python files in the project and summarize their content.")

Expected Behavior

  1. The agent will call get_directory_tree() to explore the project structure.
  2. It will filter files using find_files(["py"]) to locate Python scripts.
  3. It will use get_file_content() to analyze each file.
  4. Based on the retrieved content, it will generate a summary.

Conclusion

The CodePromptForge ToolKit provides a ready-to-use suite of tools that can be seamlessly integrated into AI agents for code reading, modification, and generation. Whether you're building LLM-based code assistants, automated reviewers, or code refactoring agents, these tools simplify and automate complex workflows.


🚀 Start developing with CodePromptForge today! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codepromptforge-0.0.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codepromptforge-0.0.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file codepromptforge-0.0.1.tar.gz.

File metadata

  • Download URL: codepromptforge-0.0.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for codepromptforge-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e82e3919fc9b54a43269946df6e2ce67c46f0ddf7b3879345e503461ea2c16ed
MD5 a41a8f40bf66fa44074bd7f35aac74c3
BLAKE2b-256 67a9d76a3de42771e4f506b686a6d8a873191456c0977271c0c2cac82d38d1eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for codepromptforge-0.0.1.tar.gz:

Publisher: python-publish.yml on RobinsonGarcia/CodePromptForge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codepromptforge-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for codepromptforge-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57a01e8dea63058e0f6d2ee9659a0d029e59d1d57f5f828649757b8a7b446fa6
MD5 f1a79d9a3487ea04e4fdaa9385ffaadf
BLAKE2b-256 43260ccb9ee3c758cc65ef998c136f4f966de9bffabda77da3d2b622d4fea651

See more details on using hashes here.

Provenance

The following attestation bundles were made for codepromptforge-0.0.1-py3-none-any.whl:

Publisher: python-publish.yml on RobinsonGarcia/CodePromptForge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page