agent: remove redundant runtime nil checks
Runtime is guaranteed non-nil by the caller (session.New ensures it). Remove defensive checks that can never fire. execServer() retains the Dispatcher nil check (agents without tools are valid).
This commit is contained in:
parent
cde16ada08
commit
0524f38db0
|
|
@ -62,9 +62,6 @@ type Agent struct {
|
||||||
|
|
||||||
// Backend returns the active backend from the runtime.
|
// Backend returns the active backend from the runtime.
|
||||||
func (ag *Agent) Backend() backend.Backend {
|
func (ag *Agent) Backend() backend.Backend {
|
||||||
if ag.runtime == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return ag.runtime.Backend
|
return ag.runtime.Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +73,7 @@ func (ag *Agent) ID() string { return ag.id }
|
||||||
|
|
||||||
// BackendName returns the name of the active backend.
|
// BackendName returns the name of the active backend.
|
||||||
func (ag *Agent) BackendName() string {
|
func (ag *Agent) BackendName() string {
|
||||||
if ag.runtime == nil || ag.runtime.Backend == nil {
|
if ag.runtime.Backend == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return ag.runtime.Backend.Name()
|
return ag.runtime.Backend.Name()
|
||||||
|
|
@ -84,7 +81,7 @@ func (ag *Agent) BackendName() string {
|
||||||
|
|
||||||
// ModelName returns the name of the active model.
|
// ModelName returns the name of the active model.
|
||||||
func (ag *Agent) ModelName() string {
|
func (ag *Agent) ModelName() string {
|
||||||
if ag.runtime == nil || ag.runtime.Backend == nil {
|
if ag.runtime.Backend == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return ag.runtime.Backend.Model()
|
return ag.runtime.Backend.Model()
|
||||||
|
|
@ -261,7 +258,7 @@ func (ag *Agent) ToolCallCount() int64 {
|
||||||
|
|
||||||
// SetSessionEnv injects session env vars into the execute server.
|
// SetSessionEnv injects session env vars into the execute server.
|
||||||
func (ag *Agent) SetSessionEnv(sessionID string) {
|
func (ag *Agent) SetSessionEnv(sessionID string) {
|
||||||
if ag.runtime == nil || ag.runtime.Dispatcher == nil {
|
if ag.runtime.Dispatcher == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
||||||
|
|
@ -276,7 +273,7 @@ func (ag *Agent) SetSessionEnv(sessionID string) {
|
||||||
|
|
||||||
// SetEnv stores an environment variable on the execute server.
|
// SetEnv stores an environment variable on the execute server.
|
||||||
func (ag *Agent) SetEnv(key, value string) {
|
func (ag *Agent) SetEnv(key, value string) {
|
||||||
if ag.runtime == nil || ag.runtime.Dispatcher == nil {
|
if ag.runtime.Dispatcher == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
||||||
|
|
@ -288,7 +285,7 @@ func (ag *Agent) SetEnv(key, value string) {
|
||||||
|
|
||||||
// Close releases agent resources (dispatcher, execute server).
|
// Close releases agent resources (dispatcher, execute server).
|
||||||
func (ag *Agent) Close() {
|
func (ag *Agent) Close() {
|
||||||
if ag.runtime == nil || ag.runtime.Dispatcher == nil {
|
if ag.runtime.Dispatcher == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
if srv, ok := ag.runtime.Dispatcher.GetServer("execute"); ok {
|
||||||
|
|
@ -477,7 +474,7 @@ func (ag *Agent) React(responseID, emoji string) error {
|
||||||
|
|
||||||
// execServer returns the execute server interface, or nil if unavailable.
|
// execServer returns the execute server interface, or nil if unavailable.
|
||||||
func (ag *Agent) execServer() interface{} {
|
func (ag *Agent) execServer() interface{} {
|
||||||
if ag.runtime == nil || ag.runtime.Dispatcher == nil {
|
if ag.runtime.Dispatcher == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
srv, _ := ag.runtime.Dispatcher.GetServer("execute")
|
srv, _ := ag.runtime.Dispatcher.GetServer("execute")
|
||||||
|
|
|
||||||
Reference in New Issue