• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kshard / thinker / 14181687602

31 Mar 2025 09:19PM UTC coverage: 61.033% (-4.9%) from 65.921%
14181687602

Pull #11

github

fogfish
add unit test for memory purge
Pull Request #11: enhance framework with composable primitives

7 of 81 new or added lines in 9 files covered. (8.64%)

390 of 639 relevant lines covered (61.03%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/agent/worker.go
1
//
2
// Copyright (C) 2025 Dmitry Kolesnikov
3
//
4
// This file may be modified and distributed under the terms
5
// of the MIT license.  See the LICENSE file for details.
6
// https://github.com/kshard/thinker
7
//
8

9
package agent
10

11
import (
12
        "github.com/kshard/chatter"
13
        "github.com/kshard/thinker"
14
        "github.com/kshard/thinker/codec"
15
        "github.com/kshard/thinker/command"
16
        "github.com/kshard/thinker/memory"
17
        "github.com/kshard/thinker/reasoner"
18
)
19

20
// The agent tailored for executing prompt driven workflow.
21
type Worker[A any] struct {
22
        *Automata[A, thinker.CmdOut]
23
        encoder  thinker.Encoder[A]
24
        registry *command.Registry
25
}
26

27
func NewWorker[A any](
28
        llm chatter.Chatter,
29
        attempts int,
30
        encoder thinker.Encoder[A],
31
        registry *command.Registry,
32
) *Worker[A] {
×
33
        registry.Register(command.Return())
×
34

×
35
        w := &Worker[A]{encoder: encoder, registry: registry}
×
36
        w.Automata = NewAutomata(
×
37
                llm,
×
38
                memory.NewStream(memory.INFINITE, `
×
39
                        You are automomous agent who uses tools to perform required tasks.
×
40
                        You are using and remember context from earlier chat history to execute the task.
×
41
                `),
×
NEW
42
                reasoner.NewEpoch(attempts, reasoner.NewCmdSeq()),
×
43
                codec.FromEncoder(w.encode),
×
44
                registry,
×
45
        )
×
46

×
47
        return w
×
48
}
×
49

50
func (w *Worker[A]) encode(in A) (prompt chatter.Prompt, err error) {
×
51
        prompt, err = w.encoder.Encode(in)
×
52
        if err == nil {
×
53
                w.registry.Harden(&prompt)
×
54
        }
×
55

56
        return
×
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc