Skip to content

Commit

Permalink
Merge pull request #588 from nkwangleiGIT/main
Browse files Browse the repository at this point in the history
feat: Add 1st version of agent support with a weather query tool
  • Loading branch information
nkwangleiGIT committed Jan 19, 2024
2 parents 00ce016 + 7ff1685 commit deeca83
Show file tree
Hide file tree
Showing 17 changed files with 933 additions and 16 deletions.
113 changes: 113 additions & 0 deletions api/app-node/agent/v1alpha1/agent_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2024 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

node "github.com/kubeagi/arcadia/api/app-node"
"github.com/kubeagi/arcadia/api/base/v1alpha1"
)

// AgentSpec defines the desired state of Agent
type AgentSpec struct {
v1alpha1.CommonSpec `json:",inline"`

AgentConfig `json:",inline"`
}

type AgentConfig struct {
// type, can be zeroShot or conversational
//+kubebuilder:default="zeroShot"
Type string `json:"type,omitempty"`
// list of allowed tools for this agent
AllowedTools []Tool `json:"allowedTools,omitempty"`
// http action like get/post
Options Options `json:"options,omitempty"`
}

// Options defines the options to be used by agent
type Options struct {
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=10
// +kubebuilder:default=5
MaxIterations int `json:"maxIterations,omitempty"`

// The options below might be used later
// prompt prompts.PromptTemplate
// outputKey string
// promptPrefix string
// formatInstructions string
// promptSuffix string
// returnIntermediateSteps bool
// memory schema.Memory
}

// Tool/Capability that this agent will use
type Tool struct {
// Name of the tool
Name string `json:"name,omitempty"`
// Map of key/value that will be passed to the tool
Params map[string]string `json:"params,omitempty"`
}

// AgentStatus defines the observed state of Agent
type AgentStatus struct {
// ObservedGeneration is the last observed generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// ConditionedStatus is the current status
v1alpha1.ConditionedStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Agent is the Schema for the Agent API
type Agent struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AgentSpec `json:"spec,omitempty"`
Status AgentStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// AgentList contains a list of Agent
type AgentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Agent `json:"items"`
}

func init() {
SchemeBuilder.Register(&Agent{}, &AgentList{})
}

var _ node.Node = (*Agent)(nil)

func (c *Agent) SetRef() {
annotations := node.SetRefAnnotations(c.GetAnnotations(), []node.Ref{node.InputRef.Len(1)}, []node.Ref{node.CommonRef.Len(1)})
if c.GetAnnotations() == nil {
c.SetAnnotations(annotations)
}
for k, v := range annotations {
c.Annotations[k] = v
}
}
41 changes: 41 additions & 0 deletions api/app-node/agent/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2024 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the arcadia v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=arcadia.kubeagi.k8s.com.cn
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
Group = "arcadia.kubeagi.k8s.com.cn"
Version = "v1alpha1"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
178 changes: 178 additions & 0 deletions api/app-node/agent/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/base/v1alpha1/worker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type WorkerSpec struct {
// - Memory
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// NodeSelectorRequirement to schedule this worker
// MatchExpressions to schedule this worker
MatchExpressions []corev1.NodeSelectorRequirement `json:"matchExpressions,omitempty"`

// Additional env to use
Expand Down
11 changes: 11 additions & 0 deletions apiserver/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/flowcontrol"
"k8s.io/utils/env"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/kubeagi/arcadia/apiserver/pkg/oidc"
Expand All @@ -38,5 +40,14 @@ func GetClient(idtoken *string) (dynamic.Interface, error) {
if err != nil {
return nil, err
}
// RateLimiter: default qps is 5,default burst is 10, so increase them
qps, _ := env.GetInt("K8S_REST_CONFIG_QPS", 50)
burst, _ := env.GetInt("K8S_REST_CONFIG_BURST", 60)
// both should be configured if need to customize
if qps > 0 && burst > 0 {
cfg.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(float32(qps), burst)
}

cfg.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(50, 60)
return dynamic.NewForConfig(cfg)
}
Loading

0 comments on commit deeca83

Please sign in to comment.