Files
ragflow/internal/harness/core/agent_loop_bridge.go
Yingfeng 956357b997 Feat: add harness-go framework —— agent core (#16045)
### What problem does this PR solve?

core module for agent layer built on top of graph engine #16039

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
2026-06-16 11:39:48 +08:00

58 lines
1.2 KiB
Go

package core
import (
"context"
"sync"
)
const bridgeCheckpointID = "__adk_turnloop_bridge_cp__"
// bridgeStore is a minimal CheckPointStore used to bridge AgentLoop with Runner
// checkpoints without using the actual Store.
type bridgeStore struct {
cpID string
data []byte
mu sync.RWMutex
}
func newBridgeStore() *bridgeStore {
return &bridgeStore{cpID: bridgeCheckpointID}
}
func newResumeBridgeStore(cpID string, data []byte) *bridgeStore {
return &bridgeStore{cpID: cpID, data: append([]byte{}, data...)}
}
func (s *bridgeStore) Get(_ context.Context, key string) ([]byte, bool, error) {
s.mu.RLock()
defer s.mu.RUnlock()
if key != s.cpID {
return nil, false, nil
}
if len(s.data) == 0 {
return nil, false, nil
}
return append([]byte{}, s.data...), true, nil
}
func (s *bridgeStore) Set(_ context.Context, key string, data []byte) error {
s.mu.Lock()
defer s.mu.Unlock()
if key == s.cpID {
s.data = append([]byte{}, data...)
}
return nil
}
func (s *bridgeStore) Delete(_ context.Context, key string) error {
s.mu.Lock()
defer s.mu.Unlock()
if key == s.cpID {
s.data = nil
}
return nil
}
var _ CheckPointStore = (*bridgeStore)(nil)
var _ CheckPointDeleter = (*bridgeStore)(nil)