Skip to content

Commit b133e62

Browse files
committed
prep-for-release
1 parent d48be28 commit b133e62

File tree

10 files changed

+331
-71
lines changed

10 files changed

+331
-71
lines changed

helm/Chart-template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v2
22
name: kagent
3-
description: A Helm chart for KAgent, built with AutogenStudio
3+
description: A Helm chart for KAgent, built with Autogen
44
type: application
55
version: ${VERSION}

helm/templates/deployment.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ spec:
5050
secretKeyRef:
5151
name: {{ .Values.openai.secretName }}
5252
key: {{ .Values.openai.secretKey }}
53+
- name: OTEL_TRACING_ENABLED
54+
value: {{ .Values.otel.tracing.enabled | quote }}
55+
- name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
56+
value: {{ .Values.otel.tracing.exporter.otlp.endpoint | quote }}
57+
- name: OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
58+
value: {{ .Values.otel.tracing.exporter.otlp.timeout | quote }}
59+
- name: OTEL_EXPORTER_OTLP_TRACES_INSECURE
60+
value: {{ .Values.otel.tracing.exporter.otlp.insecure | quote }}
5361
ports:
5462
- name: http
5563
containerPort: {{ .Values.service.ports.app.targetPort }}

helm/templates/helm-agent.yaml

+40-25
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,50 @@ spec:
1111
systemMessage: |-
1212
You are a Kubernetes expert agent specialized in cluster management and operations. Your primary responsibilities include:
1313
14-
1. Helm Operations:
15-
- Managing Helm releases (list, get details, upgrade, and uninstall)
16-
- Understanding Helm chart structures and dependencies
17-
- Validating release states and configurations
14+
1. Helm Operations:
15+
- Managing Helm releases (list, get details, upgrade, and uninstall)
16+
- Understanding Helm chart structures and dependencies
17+
- Validating release states and configurations
1818
19-
2. Kubernetes Resource Management:
20-
- Monitoring and managing various Kubernetes resources (Pods, Deployments, Services, etc.)
21-
- Analyzing resource configurations and relationships
22-
- Applying and validating Kubernetes manifests
23-
- Understanding API resource availability and versioning
19+
2. Kubernetes Resource Management:
20+
- Monitoring and managing various Kubernetes resources (Pods, Deployments, Services, etc.)
21+
- Analyzing resource configurations and relationships
22+
- Applying and validating Kubernetes manifests
23+
- Understanding API resource availability and versioning
2424
25-
3. Documentation and Troubleshooting:
26-
- Accessing and interpreting Kubernetes and related project documentation
27-
- Providing context-aware recommendations
28-
- Identifying potential issues in configurations
25+
3. Documentation and Troubleshooting:
26+
- Accessing and interpreting Kubernetes and related project documentation
27+
- Providing context-aware recommendations
28+
- Identifying potential issues in configurations
2929
30-
Always follow these principles:
31-
- Validate operations before execution
32-
- Provide clear explanations for your actions
33-
- Consider security implications
34-
- Follow Kubernetes best practices
35-
- Use appropriate tools based on the context
30+
Always follow these principles:
31+
- Validate operations before execution. For example:
32+
- If a user asks to upgrade a release, you will first check if the release exists and if it is upgradable.
33+
- If a user asks to uninstall a release, you will first check if the release exists and if it can be uninstalled.
34+
- If a user asks to change a resource, you will first check if the resource exists and see if it can be changed.
35+
- Provide clear explanations for your actions
36+
- Consider security implications
37+
- Follow Kubernetes best practices
38+
- Use appropriate tools based on the context
39+
- If you or a user needs more information about a resource, you will use the `GetResources` tool to get the resource details.
40+
- If you need to apply (create or update) a Kubernetes manifest, you will use the `ApplyManifest` tool to apply the manifest.
41+
- If you need more information about any project documentation, you will use the `QueryTool` tool to get the information.
42+
- If you need to add a new repository, you will use the `RepoAdd` tool to add the repository.
43+
- If you need to update a repository, you will use the `RepoUpdate` tool to update the repository.
44+
- If you need to list the releases, you will use the `ListReleases` tool.
45+
- If you need to get the details of a release, you will use the `GetRelease` tool.
46+
- If you need to upgrade a release, you will use the `Upgrade` tool.
47+
- If you need to uninstall a release, you will use the `Uninstall` tool.
3648
37-
When handling tasks:
38-
1. First analyze the current state
39-
2. Plan your actions
40-
3. Execute with appropriate tools
41-
4. Verify results
42-
5. Report outcomes clearly
49+
# Instructions
50+
- If user question is unclear, ask for clarification before running any tools
51+
- Always be helpful and friendly
52+
- If you don't know how to answer the question DO NOT make things up, tell the user "Sorry, I don't know how to answer that" and ask them to clarify the question further
53+
54+
# Response format
55+
- ALWAYS format your response as Markdown
56+
- Your response will include a summary of actions you took and an explanation of the result
57+
- If you created any artifacts such as files or resources, you will include those in your response as well
4358
tools:
4459
- provider: kagent.tools.helm.ListReleases
4560
- provider: kagent.tools.helm.GetRelease

helm/values.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Default values for autogenstudio
1+
# Default values for kagent
22
replicaCount: 1
33

44
global:
55
tag: ""
66

77
openai:
8-
secretName: "autogenstudio-openai"
8+
secretName: "kagent-openai"
99
apiKey: ""
1010
secretKey: "OPENAI_API_KEY"
1111

@@ -89,3 +89,12 @@ contrib:
8989
enabled: true
9090
argoRolloutsConversion:
9191
enabled: true
92+
93+
otel:
94+
tracing:
95+
enabled: false
96+
exporter:
97+
otlp:
98+
endpoint: http://localhost:4317
99+
timeout: 10
100+
insecure: true

python/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ WORKDIR /app/python
7373
COPY pyproject.toml .
7474
COPY .python-version .
7575
COPY uv.lock .
76-
COPY src src
7776
COPY README.md .
78-
RUN uv sync --frozen && \
79-
chown -R python:pythongroup /app/python
77+
RUN uv sync --frozen
78+
COPY src src
79+
RUN chown -R python:pythongroup /app/python
8080

8181
# Generate tools and agents
8282
RUN mkdir -p /root/.autogenstudio/configs
@@ -94,4 +94,4 @@ EXPOSE 8081
9494
LABEL org.opencontainers.image.source=https://github.com/kagent-dev/kagent
9595
LABEL org.opencontainers.image.description="Kagent app is the apiserver for running agents."
9696

97-
CMD ["uv", "run", "autogenstudio", "ui", "--host", "0.0.0.0", "--port", "8081"]
97+
CMD ["uv", "run", "kagent", "serve", "--host", "0.0.0.0", "--port", "8081"]

python/pyproject.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ dependencies = [
1919
"pyyaml>=6.0.2",
2020
"mcp>=1.2.0",
2121
"sqlite-vec>=0.1.0",
22-
"typer",
22+
"typer>=0.15.2",
2323
"numpy>=2.2.3",
24+
"opentelemetry-api>=1.30.0",
25+
"opentelemetry-sdk>=1.30.0",
26+
"opentelemetry-exporter-otlp-proto-grpc>=1.30.0",
27+
"opentelemetry-instrumentation-openai>= 0.38.0",
28+
"opentelemetry-instrumentation-httpx >= 0.51.0",
2429
]
2530

2631
[project.optional-dependencies]

python/src/kagent/cli.py

+42-29
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
from mcp.server.fastmcp import FastMCP
44
from pydantic import BaseModel
55

6-
from kagent.tools.argo._argo_crds import (
7-
ArgoCRDTool,
8-
ArgoCRDToolConfig,
9-
ArgoCRDToolInput,
10-
)
116
from kagent.tools.argo._argo_rollouts_k8sgw_installation import (
127
check_plugin_logs,
138
verify_gateway_plugin,
@@ -19,11 +14,13 @@
1914
verify_argo_rollouts_controller_install,
2015
verify_kubectl_plugin_install,
2116
)
22-
from kagent.tools.helm._helm import helm_list, helm_uninstall, helm_upgrade
23-
from kagent.tools.istio._istio_crds import (
24-
IstioCRDTool,
25-
IstioCRDToolConfig,
26-
IstioCRDToolInput,
17+
from kagent.tools.helm._helm import (
18+
helm_get_release,
19+
helm_list_releases,
20+
helm_repo_add,
21+
helm_repo_update,
22+
helm_uninstall,
23+
upgrade_release,
2724
)
2825
from kagent.tools.istio._istioctl import (
2926
analyze_cluster_configuration,
@@ -218,13 +215,6 @@ def argo():
218215
mcp.add_tool(promote_rollout._func, promote_rollout.name, promote_rollout.description)
219216
mcp.add_tool(set_rollout_image._func, set_rollout_image.name, set_rollout_image.description)
220217

221-
cfg = ArgoCRDToolConfig(model="gpt-4o-mini", openai_api_key=None)
222-
223-
def argo_crd_tool(input: ArgoCRDToolInput):
224-
return ArgoCRDTool(cfg).run_json(input.model_dump(), CancellationToken())
225-
226-
mcp.add_tool(argo_crd_tool, ArgoCRDTool(cfg).name, ArgoCRDTool(cfg).description)
227-
228218
mcp.run()
229219

230220

@@ -248,13 +238,6 @@ def istio():
248238
mcp.add_tool(proxy_status._func, proxy_status.name, proxy_status.description)
249239
mcp.add_tool(remote_clusters._func, remote_clusters.name, remote_clusters.description)
250240

251-
cfg = IstioCRDToolConfig(model="gpt-4o-mini", openai_api_key=None)
252-
253-
def istio_crd_tool(input: IstioCRDToolInput):
254-
return IstioCRDTool(cfg).run_json(input.model_dump(), CancellationToken())
255-
256-
mcp.add_tool(istio_crd_tool, IstioCRDTool(cfg).name, IstioCRDTool(cfg).description)
257-
258241
mcp.run()
259242

260243

@@ -287,15 +270,45 @@ def k8s():
287270

288271
@app.command()
289272
def helm():
290-
mcp.add_tool(helm_list._func, helm_list.name, helm_list.description)
291-
mcp.add_tool(helm_upgrade._func, helm_upgrade.name, helm_upgrade.description)
273+
mcp.add_tool(helm_list_releases._func, helm_list_releases.name, helm_list_releases.description)
274+
mcp.add_tool(helm_get_release._func, helm_get_release.name, helm_get_release.description)
292275
mcp.add_tool(helm_uninstall._func, helm_uninstall.name, helm_uninstall.description)
276+
mcp.add_tool(upgrade_release._func, upgrade_release.name, upgrade_release.description)
277+
mcp.add_tool(helm_repo_add._func, helm_repo_add.name, helm_repo_add.description)
278+
mcp.add_tool(helm_repo_update._func, helm_repo_update.name, helm_repo_update.description)
293279
mcp.run()
294280

295281

296-
def run():
297-
app()
282+
@app.command()
283+
def serve(
284+
host: str = "127.0.0.1",
285+
port: int = 8081,
286+
):
287+
import logging
288+
import os
289+
290+
from autogenstudio.cli import ui
291+
from opentelemetry import trace
292+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
293+
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
294+
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
295+
from opentelemetry.sdk.resources import Resource
296+
from opentelemetry.sdk.trace import TracerProvider
297+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
298+
299+
logging.basicConfig(level=logging.INFO)
300+
tracing_enabled = os.getenv("OTEL_TRACING_ENABLED", "false").lower() == "true"
301+
if tracing_enabled:
302+
logging.info("Enabling tracing")
303+
tracer_provider = TracerProvider(resource=Resource({"service.name": "kagent"}))
304+
processor = BatchSpanProcessor(OTLPSpanExporter())
305+
tracer_provider.add_span_processor(processor)
306+
trace.set_tracer_provider(tracer_provider)
307+
HTTPXClientInstrumentor().instrument()
308+
OpenAIInstrumentor().instrument()
309+
310+
ui(host=host, port=port)
298311

299312

300-
if __name__ == "__main__":
313+
def run():
301314
app()

python/src/kagent/tools/common/_llm_tool.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import logging
2+
import os
23

34
from autogen_core import CancellationToken, Component, ComponentModel
45
from autogen_core.models import ChatCompletionClient, SystemMessage, UserMessage
56
from autogen_core.tools import BaseTool
7+
from autogen_ext.models.openai import OpenAIChatCompletionClient
68
from pydantic import BaseModel, Field
79

810
logger = logging.getLogger(__name__)
@@ -11,7 +13,12 @@
1113
class LLMToolConfig(BaseModel):
1214
"""Configuration for the LLMTool."""
1315

14-
model_client: ComponentModel
16+
model_client: ComponentModel = Field(
17+
default_factory=lambda: OpenAIChatCompletionClient(
18+
model="gpt-4o-mini",
19+
).dump_component(),
20+
description="The model client to use for the LLM. If not provided, the default model client will be used.",
21+
)
1522

1623

1724
class LLMToolInput(BaseModel):

python/tests/test_generate_resource.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77
import yaml
88
from autogen_core import CancellationToken
9-
109
from autogen_ext.models.openai import OpenAIChatCompletionClient
1110

1211
from kagent.tools.k8s import GenerateResourceTool, GenerateResourceToolConfig, GenerateResourceToolInput, ResourceTypes

0 commit comments

Comments
 (0)