Merge agent and mode into one (#1689)

The concept of mode has been deprecated, there is now only the agent field in the config.

An agent can be cycled through as your primary agent with <tab> or you can spawn a subagent by @ mentioning it. if you include a description of when to use it, the primary agent will try to automatically use it

Full docs here: https://opencode.ai/docs/agents/
This commit is contained in:
Dax
2025-08-07 16:32:12 -04:00
committed by GitHub
parent 12f1ad521f
commit c34aec060f
42 changed files with 1755 additions and 930 deletions

View File

@@ -190,6 +190,113 @@ func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.
return
}
type AgentPart struct {
ID string `json:"id,required"`
MessageID string `json:"messageID,required"`
Name string `json:"name,required"`
SessionID string `json:"sessionID,required"`
Type AgentPartType `json:"type,required"`
Source AgentPartSource `json:"source"`
JSON agentPartJSON `json:"-"`
}
// agentPartJSON contains the JSON metadata for the struct [AgentPart]
type agentPartJSON struct {
ID apijson.Field
MessageID apijson.Field
Name apijson.Field
SessionID apijson.Field
Type apijson.Field
Source apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentPart) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentPartJSON) RawJSON() string {
return r.raw
}
func (r AgentPart) implementsPart() {}
type AgentPartType string
const (
AgentPartTypeAgent AgentPartType = "agent"
)
func (r AgentPartType) IsKnown() bool {
switch r {
case AgentPartTypeAgent:
return true
}
return false
}
type AgentPartSource struct {
End int64 `json:"end,required"`
Start int64 `json:"start,required"`
Value string `json:"value,required"`
JSON agentPartSourceJSON `json:"-"`
}
// agentPartSourceJSON contains the JSON metadata for the struct [AgentPartSource]
type agentPartSourceJSON struct {
End apijson.Field
Start apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AgentPartSource) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r agentPartSourceJSON) RawJSON() string {
return r.raw
}
type AgentPartInputParam struct {
Name param.Field[string] `json:"name,required"`
Type param.Field[AgentPartInputType] `json:"type,required"`
ID param.Field[string] `json:"id"`
Source param.Field[AgentPartInputSourceParam] `json:"source"`
}
func (r AgentPartInputParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AgentPartInputParam) implementsSessionChatParamsPartUnion() {}
type AgentPartInputType string
const (
AgentPartInputTypeAgent AgentPartInputType = "agent"
)
func (r AgentPartInputType) IsKnown() bool {
switch r {
case AgentPartInputTypeAgent:
return true
}
return false
}
type AgentPartInputSourceParam struct {
End param.Field[int64] `json:"end,required"`
Start param.Field[int64] `json:"start,required"`
Value param.Field[string] `json:"value,required"`
}
func (r AgentPartInputSourceParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type AssistantMessage struct {
ID string `json:"id,required"`
Cost float64 `json:"cost,required"`
@@ -855,11 +962,13 @@ type Part struct {
Cost float64 `json:"cost"`
Filename string `json:"filename"`
// This field can have the runtime type of [[]string].
Files interface{} `json:"files"`
Hash string `json:"hash"`
Mime string `json:"mime"`
Snapshot string `json:"snapshot"`
Source FilePartSource `json:"source"`
Files interface{} `json:"files"`
Hash string `json:"hash"`
Mime string `json:"mime"`
Name string `json:"name"`
Snapshot string `json:"snapshot"`
// This field can have the runtime type of [FilePartSource], [AgentPartSource].
Source interface{} `json:"source"`
// This field can have the runtime type of [ToolPartState].
State interface{} `json:"state"`
Synthetic bool `json:"synthetic"`
@@ -886,6 +995,7 @@ type partJSON struct {
Files apijson.Field
Hash apijson.Field
Mime apijson.Field
Name apijson.Field
Snapshot apijson.Field
Source apijson.Field
State apijson.Field
@@ -916,13 +1026,13 @@ func (r *Part) UnmarshalJSON(data []byte) (err error) {
// for more type safety.
//
// Possible runtime types of the union are [TextPart], [FilePart], [ToolPart],
// [StepStartPart], [StepFinishPart], [SnapshotPart], [PartPatchPart].
// [StepStartPart], [StepFinishPart], [SnapshotPart], [PartPatchPart], [AgentPart].
func (r Part) AsUnion() PartUnion {
return r.union
}
// Union satisfied by [TextPart], [FilePart], [ToolPart], [StepStartPart],
// [StepFinishPart], [SnapshotPart] or [PartPatchPart].
// [StepFinishPart], [SnapshotPart], [PartPatchPart] or [AgentPart].
type PartUnion interface {
implementsPart()
}
@@ -966,6 +1076,11 @@ func init() {
Type: reflect.TypeOf(PartPatchPart{}),
DiscriminatorValue: "patch",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(AgentPart{}),
DiscriminatorValue: "agent",
},
)
}
@@ -1025,11 +1140,12 @@ const (
PartTypeStepFinish PartType = "step-finish"
PartTypeSnapshot PartType = "snapshot"
PartTypePatch PartType = "patch"
PartTypeAgent PartType = "agent"
)
func (r PartType) IsKnown() bool {
switch r {
case PartTypeText, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot, PartTypePatch:
case PartTypeText, PartTypeFile, PartTypeTool, PartTypeStepStart, PartTypeStepFinish, PartTypeSnapshot, PartTypePatch, PartTypeAgent:
return true
}
return false
@@ -2080,8 +2196,8 @@ type SessionChatParams struct {
ModelID param.Field[string] `json:"modelID,required"`
Parts param.Field[[]SessionChatParamsPartUnion] `json:"parts,required"`
ProviderID param.Field[string] `json:"providerID,required"`
Agent param.Field[string] `json:"agent"`
MessageID param.Field[string] `json:"messageID"`
Mode param.Field[string] `json:"mode"`
System param.Field[string] `json:"system"`
Tools param.Field[map[string]bool] `json:"tools"`
}
@@ -2095,7 +2211,8 @@ type SessionChatParamsPart struct {
ID param.Field[string] `json:"id"`
Filename param.Field[string] `json:"filename"`
Mime param.Field[string] `json:"mime"`
Source param.Field[FilePartSourceUnionParam] `json:"source"`
Name param.Field[string] `json:"name"`
Source param.Field[interface{}] `json:"source"`
Synthetic param.Field[bool] `json:"synthetic"`
Text param.Field[string] `json:"text"`
Time param.Field[interface{}] `json:"time"`
@@ -2108,7 +2225,7 @@ func (r SessionChatParamsPart) MarshalJSON() (data []byte, err error) {
func (r SessionChatParamsPart) implementsSessionChatParamsPartUnion() {}
// Satisfied by [TextPartInputParam], [FilePartInputParam],
// Satisfied by [TextPartInputParam], [FilePartInputParam], [AgentPartInputParam],
// [SessionChatParamsPart].
type SessionChatParamsPartUnion interface {
implementsSessionChatParamsPartUnion()
@@ -2117,13 +2234,14 @@ type SessionChatParamsPartUnion interface {
type SessionChatParamsPartsType string
const (
SessionChatParamsPartsTypeText SessionChatParamsPartsType = "text"
SessionChatParamsPartsTypeFile SessionChatParamsPartsType = "file"
SessionChatParamsPartsTypeText SessionChatParamsPartsType = "text"
SessionChatParamsPartsTypeFile SessionChatParamsPartsType = "file"
SessionChatParamsPartsTypeAgent SessionChatParamsPartsType = "agent"
)
func (r SessionChatParamsPartsType) IsKnown() bool {
switch r {
case SessionChatParamsPartsTypeText, SessionChatParamsPartsTypeFile:
case SessionChatParamsPartsTypeText, SessionChatParamsPartsTypeFile, SessionChatParamsPartsTypeAgent:
return true
}
return false