-
Notifications
You must be signed in to change notification settings - Fork 5
feat: agent interface and source layer (Phase 0a — T0.1, T0.2, T0.2a, T0.2b) #36
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
Open
canonical-muhammadbassiony
wants to merge
1
commit into
feature/bauer-v2
Choose a base branch
from
feat/phase-0a-agent-source
base: feature/bauer-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ import ( | |
| "bauer/cmd/app/core/middleware" | ||
| "bauer/cmd/app/types" | ||
| v1 "bauer/cmd/app/v1" | ||
| "bauer/internal/copilotcli" | ||
| "bauer/internal/orchestrator" | ||
| "bauer/internal/source" | ||
| "bauer/internal/workflow" | ||
| "fmt" | ||
| "log/slog" | ||
|
|
@@ -20,22 +22,36 @@ func run() error { | |
| slog.Info("startup", "status", "initializing API") | ||
| defer slog.Info("shutdown complete") | ||
|
|
||
| orchestrator := orchestrator.NewOrchestrator() | ||
| cfg, err := types.LoadConfig() | ||
| if err != nil { | ||
| slog.Error("failed to load config", "error", err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| cwd, err := os.Getwd() | ||
| if err != nil { | ||
| slog.Error("failed to get working directory", "error", err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| copilotAgent, err := copilotcli.NewClient(cwd) | ||
| if err != nil { | ||
| slog.Error("failed to create Copilot client", "error", err.Error()) | ||
| return err | ||
| } | ||
|
|
||
| sources := source.NewManager(cfg.CredentialsPath) | ||
| orch := orchestrator.New(copilotAgent, sources) | ||
|
|
||
|
Comment on lines
+43
to
+45
Collaborator
Author
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. Same — later branches (phase-3, T3.2) remove per-request credentials entirely from the API request body. The Manager is initialized at startup with the service account path, and that becomes the only source. This interim state goes away. |
||
| rc := types.RouteConfig{ | ||
| APIConfig: *cfg, | ||
| Orchestrator: orchestrator, | ||
| Orchestrator: orch, | ||
| } | ||
|
|
||
| mux := http.NewServeMux() | ||
| mux.HandleFunc("/api/v1/job", v1.JobPost(rc)) | ||
| mux.HandleFunc("/api/v1/health", v1.GetHealth) | ||
| mux.HandleFunc("/api/v1/workflow", workflow.ExecuteWorkflowHandler(orchestrator)) | ||
| mux.HandleFunc("/api/v1/workflow", workflow.ExecuteWorkflowHandler(orch)) | ||
| slog.Info("starting server", "address", ":8090") | ||
| err = http.ListenAndServe(":8090", middleware.RequestTrace(mux)) | ||
|
|
||
|
|
@@ -53,3 +69,4 @@ func main() { | |
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
| // internal/agent/agent.go | ||
| package agent | ||
|
|
||
| import "context" | ||
|
|
||
| // Agent is the interface any AI execution backend must implement. | ||
| // copilotcli.Client implements this; future backends (REST-based agents, | ||
| // test mocks, etc.) can implement it without touching the orchestrator. | ||
| type Agent interface { | ||
| // Start boots the agent (e.g. starts the Copilot SDK server process). | ||
| // Must be called before any other method. Callers should defer Stop(). | ||
| Start(ctx context.Context) error | ||
|
|
||
| // ExecuteChunk sends a single chunk prompt file to the agent and returns | ||
| // the full text output. chunkNum is for logging/display only. | ||
| ExecuteChunk(ctx context.Context, chunkPath string, chunkNum int, model string) (string, error) | ||
|
|
||
| // GenerateSummary produces a summary of all chunk outputs. | ||
| // Only called when there are multiple chunks. | ||
| GenerateSummary(ctx context.Context, outputs []string, model string) (string, error) | ||
|
|
||
| // Stop shuts the agent down cleanly. Safe to call after a failed Start. | ||
| Stop() error | ||
| } |
This file contains hidden or 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,50 @@ | ||
| package agent_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "bauer/internal/agent" | ||
| ) | ||
|
|
||
| // Compile-time check that MockAgent implements Agent. | ||
| var _ agent.Agent = agent.MockAgent{} | ||
|
|
||
| func TestMockAgent_Start(t *testing.T) { | ||
| a := agent.MockAgent{} | ||
| if err := a.Start(context.Background()); err != nil { | ||
| t.Fatalf("Start() = %v, want nil", err) | ||
| } | ||
| } | ||
|
|
||
| func TestMockAgent_Stop(t *testing.T) { | ||
| a := agent.MockAgent{} | ||
| if err := a.Stop(); err != nil { | ||
| t.Fatalf("Stop() = %v, want nil", err) | ||
| } | ||
| } | ||
|
|
||
| func TestMockAgent_ExecuteChunk(t *testing.T) { | ||
| a := agent.MockAgent{} | ||
| out, err := a.ExecuteChunk(context.Background(), "chunk-1.md", 1, "gpt-4") | ||
| if err != nil { | ||
| t.Fatalf("ExecuteChunk() error = %v", err) | ||
| } | ||
| if out == "" { | ||
| t.Fatal("ExecuteChunk() returned empty output") | ||
| } | ||
| if want := "mock output for chunk chunk-1.md"; out != want { | ||
| t.Fatalf("ExecuteChunk() = %q, want %q", out, want) | ||
| } | ||
| } | ||
|
|
||
| func TestMockAgent_GenerateSummary(t *testing.T) { | ||
| a := agent.MockAgent{} | ||
| summary, err := a.GenerateSummary(context.Background(), []string{"output1", "output2"}, "gpt-4") | ||
| if err != nil { | ||
| t.Fatalf("GenerateSummary() error = %v", err) | ||
| } | ||
| if want := "mock summary"; summary != want { | ||
| t.Fatalf("GenerateSummary() = %q, want %q", summary, want) | ||
| } | ||
| } |
This file contains hidden or 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,16 @@ | ||
| // internal/agent/mock.go | ||
| package agent | ||
|
|
||
| import "context" | ||
|
|
||
| // MockAgent is a no-op Agent implementation for use in tests. | ||
| type MockAgent struct{} | ||
|
|
||
| func (m MockAgent) Start(_ context.Context) error { return nil } | ||
| func (m MockAgent) ExecuteChunk(_ context.Context, chunkPath string, _ int, _ string) (string, error) { | ||
| return "mock output for chunk " + chunkPath, nil | ||
| } | ||
| func (m MockAgent) GenerateSummary(_ context.Context, _ []string, _ string) (string, error) { | ||
| return "mock summary", nil | ||
| } | ||
| func (m MockAgent) Stop() error { return nil } |
This file contains hidden or 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 hidden or 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.
Agreed this is a concern for concurrent requests. It is addressed in later branches (phase-3/phase-4) where the API handler creates a fresh agent per workflow execution. The shared agent pattern here is interim.