Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code-template): Add Code Template System and Tool Calling Infrastructure #302

Closed

Conversation

thecodacus
Copy link
Collaborator

@thecodacus thecodacus commented Nov 16, 2024

Add Code Template System and Tool Calling Infrastructure

Overview

This PR introduces two major architectural enhancements:

  1. A code template system for project scaffolding
  2. A foundational infrastructure for AI tool calling with an agent-based architecture

These changes enable more sophisticated project initialization and lay the groundwork for AI-driven tooling capabilities.

Key Changes

1. Template System Implementation

  • Added project template import functionality
  • Implemented GitHub-based template fetching
  • Added template configuration and management
  • Introduced template ignore patterns for selective imports
  • Added support for template-specific prompts

2. Tool Calling Infrastructure

  • Implemented base agent architecture for tool execution
  • Added tool calling parser and execution pipeline
  • Integrated tool configuration management
  • Added support for agent-based routing and coordination
  • Implemented template variables system for dynamic prompting

3. Agent System

  • Added AgentPromptGenerator for structured prompt generation
  • Implemented AgentOutputParser for processing tool calls
  • Added coordinator agent for query routing
  • Implemented project scaffolding agent
  • Added support for agent registration and management

4. UI Enhancements

  • Added tool configuration toggle in chat interface
  • Implemented tool execution status display
  • Added template selection interface
  • Enhanced message parsing for tool responses
  • Added support for tool calling visualization

Technical Implementation

Agent Architecture

  • Base agent class with configurable tools and parameters
  • XML-based tool call protocol for structured communication
  • Support for template variables and dynamic prompt generation
  • Coordinator agent for intelligent query routing

Template System

  • GitHub API integration for template fetching
  • Support for .bolt configuration directory
  • Template ignore patterns for selective imports
  • Custom prompt support for templates

Tool Execution Pipeline

  1. Tool call parsing and validation
  2. Agent selection and routing
  3. Parameter validation
  4. Tool execution
  5. Response formatting and streaming

Testing

  • Tested template import functionality
  • Verified tool calling pipeline
  • Tested agent routing system
  • Verified template ignore patterns
  • Tested tool configuration persistence

Migration Impact

  • No breaking changes for existing chat functionality
  • Tool calling requires explicit opt-in via toggle
  • Template system is additive to existing functionality
  • Existing message parsing remains unchanged

Future Enhancements

  • Add support for more complex tool chains
  • Enhance template management system
  • Add more specialized agents
  • Improve tool execution visualization
  • Add support for concurrent tool execution

Preview

Code.Template.Demo.mp4

@thecodacus thecodacus changed the title Artifact based tool calling feat(code-template): Add Code Template System and Tool Calling Infrastructure Nov 16, 2024
@thecodacus thecodacus marked this pull request as ready for review November 16, 2024 06:46
@thecodacus
Copy link
Collaborator Author

@wonderwhy-er , sorry but I tried to make the changes as little as possible 😅

@thecodacus
Copy link
Collaborator Author

Also this approach is text based, to it can be used by any llm, as long as it follows the structured output and does not get confused. that require prompt tuning which can be done in separate task

we can now add agents for github project import or commit, using this framework

@wonderwhy-er
Copy link
Collaborator

Ok, will need to take a deeper look in to how it works

@thecodacus
Copy link
Collaborator Author

this is an example of git import using the tooling framework

Git.Import.using.Tool.Architecture.mp4

@wonderwhy-er
Copy link
Collaborator

Ahh its still big, will take time to fully review...

@champ2050
Copy link

@thecodacus Awesome work! Thank you for your contribution. Have you had a chance to check out Microsoft's Magnetic-One? It includes an orchestrator that passes commands to specific agents, each designed to handle particular tasks. If you could take a look at it, that might make a fantastic addition to this project. Magnetic-One was recently released, so not many people have seen it yet, but it works really well. Thanks again for your awesome work, I really appreciate it!

@thecodacus
Copy link
Collaborator Author

no I didn't get the chance to see that yet. will definitely check that

@Prathamesh-Shanbhag
Copy link

This was an awesome addition - Now all I look forward to is the ability to have attachments as reference to the prompts and one click deploy to vercel or other similar platforms!!

@wonderwhy-er
Copy link
Collaborator

I did not even notice it had github integration in some form.
If I understand it correctly its for local use only, or one who hosts would need to add his key in there.

Considering its not oauth based all users of hosted app will have 5k requests per hour
https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28

We still need to get to oauth variant to work at some point.

@thecodacus
Copy link
Collaborator Author

thecodacus commented Nov 23, 2024

I did not even notice it had github integration in some form. If I understand it correctly its for local use only, or one who hosts would need to add his key in there.

Considering its not oauth based all users of hosted app will have 5k requests per hour https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28

We still need to get to oauth variant to work at some point.

Yes, for code template system, template needs to be downloaded from github. we will need the key, but the api also has some allowance without any key as well. in future we can also modify the agent code to use the tarball download. that will not require any oauth or api key at all

for the github project import demo that i showed in the threaded video, was just to show case what we can do with this system, this PR does not contain the github agent included. that is something I just made with this system quickly to showcase

@adriano2023666
Copy link

I am currently facing a NotFoundError in the application, and I need assistance in resolving it. The error message is as follows:

php
Copiar código
NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
at insertBefore (http://localhost:5173/node_modules/.vite/deps/chunk-TLFX46WQ.js?v=b44fa53c:15324:26)
at insertOrAppendPlacementNode (http://localhost:5173/node_modules/.vite/deps/chunk-TLFX46WQ.js?v=b44fa53c:24310:15)
at commitPlacement (http://localhost:5173/node_modules/.vite/deps/chunk-TLFX46WQ.js?v=b44fa53c:24267:15)
at commitReconciliationEffects (http://localhost:5173/node_modules/.vite/deps/chunk-TLFX46WQ.js?v=b44fa53c:24784:15)
...
The issue seems to be related to the insertBefore method in the DOM, where the new node cannot be inserted because the specified reference node is not a child of the parent node. This is causing the application to behave unexpectedly, and it's affecting the UI by preventing certain elements from being rendered or placed correctly.

Could anyone help me understand what might be causing this error and guide me on how to resolve
bandicam 2024-11-23 17-54-48-349

Copy link
Collaborator

@mrsimpson mrsimpson left a comment

Choose a reason for hiding this comment

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

Dear @thecodacus ,

First off: I am not a maintainer of this project nor have I fully understood all your decisions.
But I very much appreciate your contribution and wanted to show this be reviewing it.
Your PR is quite huge, so I am afraid it might take some time to get it merged. Therefore, I focused on "how could this be easier to merge"

Two things I noted which I personally would welcome in order to keep this project maintainable:

  • Along implementing your extensions, you added some improvements (such as adding proper types) which I appreciate a lot. This could be very well be one (or even multiple) separate small PRs.
  • I do think that modifying files from an upstream should be reduced as much as possible. Thus, I do think it would help to move blocks of code into separate small files and place them in dedicated folders for tool or agent.

In general, I do like your work a lot and hope my feedback helps to get this merged quicker.

Cheers, Oliver

app/components/chat/APIKeyManager.tsx Show resolved Hide resolved
@@ -85,6 +86,7 @@ interface BaseChatProps {
sendMessage?: (event: React.UIEvent, messageInput?: string) => void;
handleInputChange?: (event: React.ChangeEvent<HTMLTextAreaElement>) => void;
enhancePrompt?: () => void;

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are some formatting artifacts. Please lint:fix the source to keep the diff small as possible

@@ -113,8 +115,13 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
) => {
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
const [apiKeys, setApiKeys] = useState<Record<string, string>>({});
const [toolConfig, setToolConfig] = useState<IToolsConfig>({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for making it an interface 👍

@@ -136,6 +143,25 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
});
}, []);

useEffect(() => {
const config = Cookies.get('bolt.toolsConfig');
Copy link
Collaborator

Choose a reason for hiding this comment

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

WDYT about moving this whole piece of logic into a separate file in components/tools and to have only a single-line-modification here?

/>
{provider && (
<div className="flex justify-between items-center">
Copy link
Collaborator

Choose a reason for hiding this comment

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

another candidate for a separate file


export abstract class BaseTool {
protected webcontainer: Promise<WebContainer>;
constructor(webcontainerPromise: Promise<WebContainer>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't each tool have at least a name so it can identify itself in tool messages

Edit: Now I see that the agent has a name. I think I misunderstood what tool and agents are. Could you clarify this a bit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

you said this was not actually part of this PR, as far as I understood ;)

But since this is a viable implementation and doesn't add to the overall modifications, I appreciate it being in here!

@@ -117,6 +117,12 @@ const PROVIDER_LIST: ProviderInfo[] = [
}
];

const codeTemplates: TemplateInfo[] = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be part of either the agent or the toolConfig? I think it should outside this file at least

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is also actually independent from this PR, isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also here: Move it to app/lib/tools/types.ts . I doubt that a single types file is best practice.

including one review suggestion

Co-authored-by: Oliver Jägle <[email protected]>
Copy link

github-actions bot commented Dec 6, 2024

This pull request has been marked as stale due to inactivity. If no further activity occurs, it will be closed in 7 days.

@github-actions github-actions bot added the stale The pull / issue is stale and will be closed soon label Dec 6, 2024
@dustinwloring1988 dustinwloring1988 removed the stale The pull / issue is stale and will be closed soon label Dec 8, 2024
@thecodacus thecodacus closed this Dec 21, 2024
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.

7 participants