-
-
Notifications
You must be signed in to change notification settings - Fork 154
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: add agentic workflows to the plugin #35
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b7d1bd2
wip: start on agentic workflows
olimorris e06b1c7
tweak workflows
olimorris 47e5a1f
update README
olimorris 6f68775
start scoping out agents
olimorris 07fb727
docs: update README
olimorris 982449d
docs: update README
olimorris 8fe53eb
workflows now work
olimorris 9ef5786
docs: update README
olimorris f855799
docs: update README
olimorris 8e86496
add refactoring workflow
olimorris 781a392
docs: update README
olimorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,6 +289,124 @@ M.static.actions = { | |
}, | ||
}, | ||
}, | ||
{ | ||
name = "Agentic Workflows...", | ||
strategy = "chat", | ||
description = "Workflows to improve the performance of your LLM", | ||
picker = { | ||
prompt = "Select a workflow", | ||
items = { | ||
{ | ||
name = "Code a feature - Outline, draft, consider and then revise", | ||
callback = function(context) | ||
local agent = require("codecompanion.agent") | ||
return agent | ||
.new({ | ||
context = context, | ||
strategy = "chat", | ||
}) | ||
:workflow({ | ||
{ | ||
role = "system", | ||
content = "You are an expert coder and helpful assistant who can help outline, draft, consider and revise code for the " | ||
.. context.filetype | ||
.. " language.", | ||
start = true, | ||
}, | ||
{ | ||
condition = function() | ||
return context.is_visual | ||
end, | ||
contains_code = true, | ||
role = "user", | ||
content = "Here is some relevant context: " .. send_code(context), | ||
start = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "I want you to help me code a feature. Before we write any code let's outline how we'll architect and implement the feature with the context you already have. The feature I'd like to add is ", | ||
start = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Thanks. Now let's draft the code for the feature.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Great. Now let's consider the code. I'd like you to check it carefully for correctness, style, and efficiency, and give constructive criticism for how to improve it.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Thanks. Now let's revise the code based on the feedback.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "For clarity, can you show the final code without any explanations?", | ||
auto_submit = true, | ||
}, | ||
Comment on lines
+340
to
+349
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is where we generate the final output, what do you think about just using one prompt? |
||
}) | ||
end, | ||
}, | ||
{ | ||
name = "Refactor some code - Outline, draft, consider and then revise", | ||
callback = function(context) | ||
local agent = require("codecompanion.agent") | ||
return agent | ||
.new({ | ||
context = context, | ||
strategy = "chat", | ||
}) | ||
:workflow({ | ||
{ | ||
role = "system", | ||
content = "You are an expert coder and helpful assistant who can help outline, draft, consider and revise code for the " | ||
.. context.filetype | ||
.. " language.", | ||
start = true, | ||
}, | ||
{ | ||
condition = function() | ||
return context.is_visual | ||
end, | ||
contains_code = true, | ||
role = "user", | ||
content = "Here is some relevant context: " .. send_code(context), | ||
start = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "I want you to help me with a refactor. Before we write any code let's outline how we'll architect and implement the code with the context you already have. What I'm looking to achieve is ", | ||
start = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Thanks. Now let's draft the code for the refactor.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Great. Now let's consider the code. I'd like you to check it carefully for correctness, style, and efficiency, and give constructive criticism for how to improve it.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "Thanks. Now let's revise the code based on the feedback.", | ||
auto_submit = true, | ||
}, | ||
{ | ||
role = "user", | ||
content = "For clarity, can you show the final code without any explanations?", | ||
auto_submit = true, | ||
}, | ||
}) | ||
end, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name = "Inline code ...", | ||
strategy = "inline", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
local config = require("codecompanion.config") | ||
|
||
---@class CodeCompanion.Agent | ||
local Agent = {} | ||
|
||
---@class CodeCompanion.AgentArgs | ||
---@field context table | ||
---@field strategy string | ||
|
||
---@param args table | ||
---@return CodeCompanion.Agent | ||
function Agent.new(args) | ||
return setmetatable(args, { __index = Agent }) | ||
end | ||
|
||
---@param prompts table | ||
function Agent:workflow(prompts) | ||
local starting_prompts = {} | ||
local workflow_prompts = {} | ||
|
||
for _, prompt in ipairs(prompts) do | ||
if prompt.start then | ||
if | ||
(type(prompt.condition) == "function" and not prompt.condition()) | ||
or (prompt.contains_code and not config.options.send_code) | ||
then | ||
goto continue | ||
end | ||
|
||
table.insert(starting_prompts, { | ||
role = prompt.role, | ||
content = prompt.content, | ||
}) | ||
else | ||
table.insert(workflow_prompts, { | ||
role = prompt.role, | ||
content = prompt.content, | ||
auto_submit = prompt.auto_submit, | ||
}) | ||
end | ||
::continue:: | ||
end | ||
|
||
return require("codecompanion.strategies.chat").new({ | ||
type = "chat", | ||
messages = starting_prompts, | ||
workflow = workflow_prompts, | ||
show_buffer = true, | ||
}) | ||
end | ||
|
||
return Agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some prompting techniques that could be helpful for getting better answers. This is something I've gotten from Jeremy Howard at fast.ai:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great suggestions. Would you PR these?