MCPcopy
hub / github.com/google/ax / Connect

Method Connect

examples/docker_agent/main.go:42–163  ·  view source on GitHub ↗
(stream grpc.BidiStreamingServer[proto.AgentMessage, proto.AgentMessage])

Source from the content-addressed store, hash-verified

40}
41
42func (s *server) Connect(stream grpc.BidiStreamingServer[proto.AgentMessage, proto.AgentMessage]) error {
43 incoming, err := stream.Recv()
44 if err == io.EOF {
45 return nil
46 }
47 if err != nil {
48 return err
49 }
50
51 start := incoming.GetStart()
52 if start == nil {
53 return errors.New("missing start message")
54 }
55
56 contents := protoToContents(start.Messages)
57
58 for {
59 model := os.Getenv("AX_GEMINI_MODEL")
60 if model == "" {
61 model = "gemini-3.5-flash"
62 }
63 resp, err := s.genaiClient.Models.GenerateContent(stream.Context(), model, contents, &genai.GenerateContentConfig{
64 SystemInstruction: genai.Text("You are DockerAgent, an agent specialized in writing Dockerfiles. Use the docker-writer skill to fulfill requests. Keep responses concise.")[0],
65 Tools: []*genai.Tool{skills.BuildTool(s.skillsExecutor.SkillNames())},
66 })
67 if err != nil {
68 return fmt.Errorf("failed to generate content: %w", err)
69 }
70
71 if len(resp.Candidates) == 0 {
72 return errors.New("no candidates from Gemini")
73 }
74 candidate := resp.Candidates[0]
75
76 var keepLooping bool
77 var functionCall *genai.FunctionCall
78 var thoughtSignature []byte
79
80 for _, part := range candidate.Content.Parts {
81 if part.FunctionCall != nil {
82 functionCall = part.FunctionCall
83 thoughtSignature = part.ThoughtSignature
84 break
85 }
86 }
87
88 if functionCall != nil {
89 if functionCall.ID == "" {
90 functionCall.ID = uuid.NewString()
91 }
92
93 // Handle skill call
94 result, err := s.skillsExecutor.HandleCall(stream.Context(), functionCall)
95 if err != nil {
96 return fmt.Errorf("failed to handle skill call: %w", err)
97 }
98
99 // Append function call and response to history

Callers

nothing calls this directly

Calls 6

BuildToolFunction · 0.92
GetStartMethod · 0.80
SkillNamesMethod · 0.80
protoToContentsFunction · 0.70
GenerateContentMethod · 0.65
HandleCallMethod · 0.65

Tested by

no test coverage detected