|
|
@@ -314,6 +314,129 @@ def cmd_run(args):
|
|
|
print(" Duration: {}ms".format(usage.get("duration_ms", 0)))
|
|
|
|
|
|
|
|
|
+# ============================================================
|
|
|
+# Commands: chat (interactive)
|
|
|
+# ============================================================
|
|
|
+
|
|
|
+def cmd_chat(args):
|
|
|
+ """Interactive chat with an agent via PaaS API."""
|
|
|
+ target = args.target
|
|
|
+
|
|
|
+ # Resolve agent: by ID, by name, or auto-detect
|
|
|
+ if not target:
|
|
|
+ # Auto: list agents, pick the first (or only) one
|
|
|
+ data = api("GET", "/api/v1/agents")
|
|
|
+ agents = data.get("agents", [])
|
|
|
+ if not agents:
|
|
|
+ print("No agents found. Create one first:")
|
|
|
+ print(" agentpaas agent create --name lambda --config agent-config.yml")
|
|
|
+ return
|
|
|
+ if len(agents) == 1:
|
|
|
+ agent = agents[0]
|
|
|
+ else:
|
|
|
+ print("Multiple agents found. Select one:\n")
|
|
|
+ for i, a in enumerate(agents):
|
|
|
+ print(" [{}] {} — {} (v{})".format(i + 1, a["id"], a["name"], a.get("current_version", "?")))
|
|
|
+ print()
|
|
|
+ try:
|
|
|
+ choice = input("Enter number or agent ID: ").strip()
|
|
|
+ if choice.isdigit() and 1 <= int(choice) <= len(agents):
|
|
|
+ agent = agents[int(choice) - 1]
|
|
|
+ else:
|
|
|
+ agent = next((a for a in agents if a["id"] == choice), agents[0])
|
|
|
+ except (EOFError, KeyboardInterrupt):
|
|
|
+ return
|
|
|
+ elif target.startswith("ag_"):
|
|
|
+ # By ID
|
|
|
+ agent = api("GET", "/api/v1/agents/{}".format(target))
|
|
|
+ else:
|
|
|
+ # By name: search
|
|
|
+ data = api("GET", "/api/v1/agents")
|
|
|
+ agents = data.get("agents", [])
|
|
|
+ agent = next((a for a in agents if a.get("name", "").lower() == target.lower()), None)
|
|
|
+ if not agent:
|
|
|
+ # Fuzzy match
|
|
|
+ agent = next((a for a in agents if target.lower() in a.get("name", "").lower()), None)
|
|
|
+ if not agent:
|
|
|
+ print("Agent '{}' not found. Available agents:".format(target))
|
|
|
+ for a in agents:
|
|
|
+ print(" {} — {}".format(a["id"], a["name"]))
|
|
|
+ return
|
|
|
+
|
|
|
+ agent_id = agent["id"]
|
|
|
+ agent_name = agent.get("name", agent_id)
|
|
|
+ agent_version = agent.get("current_version", "?")
|
|
|
+
|
|
|
+ print()
|
|
|
+ print("╔══════════════════════════════════════════════════════════╗")
|
|
|
+ print("║ 🐑 {} — via AgentPaaS".format(agent_name.ljust(44))[:56] + " ║")
|
|
|
+ print("║ Agent: {} Version: {}".format(agent_id, agent_version).ljust(56) + " ║")
|
|
|
+ print("╠══════════════════════════════════════════════════════════╣")
|
|
|
+ print("║ 输入消息开始对话,exit 退出,history 查看历史 ║")
|
|
|
+ print("╚══════════════════════════════════════════════════════════╝")
|
|
|
+ print()
|
|
|
+
|
|
|
+ conversation = []
|
|
|
+
|
|
|
+ while True:
|
|
|
+ try:
|
|
|
+ user_input = input("You: ").strip()
|
|
|
+ except (EOFError, KeyboardInterrupt):
|
|
|
+ print("\n👋 对话结束")
|
|
|
+ break
|
|
|
+
|
|
|
+ if not user_input:
|
|
|
+ continue
|
|
|
+
|
|
|
+ if user_input.lower() in ("exit", "quit", "bye"):
|
|
|
+ print("👋 对话结束")
|
|
|
+ break
|
|
|
+
|
|
|
+ if user_input.lower() == "history":
|
|
|
+ if not conversation:
|
|
|
+ print(" (无对话历史)")
|
|
|
+ else:
|
|
|
+ for entry in conversation:
|
|
|
+ role = entry["role"]
|
|
|
+ content = entry["content"][:150]
|
|
|
+ print(" [{}] {}".format(role, content))
|
|
|
+ print()
|
|
|
+ continue
|
|
|
+
|
|
|
+ # Build input with conversation history
|
|
|
+ if conversation:
|
|
|
+ history_text = "\n".join(
|
|
|
+ "[{}] {}".format(e["role"], e["content"][:300])
|
|
|
+ for e in conversation[-10:] # last 10 turns
|
|
|
+ )
|
|
|
+ full_input = "=== 对话历史 ===\n{}\n=== 历史结束 ===\n\n[用户] {}".format(
|
|
|
+ history_text, user_input
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ full_input = user_input
|
|
|
+
|
|
|
+ conversation.append({"role": "用户", "content": user_input})
|
|
|
+
|
|
|
+ # Call PaaS API
|
|
|
+ print()
|
|
|
+ t0 = time.time()
|
|
|
+ data = api("POST", "/api/v1/agents/{}/run".format(agent_id),
|
|
|
+ {"input": full_input})
|
|
|
+ elapsed = time.time() - t0
|
|
|
+
|
|
|
+ output = data.get("output", "")
|
|
|
+ usage = data.get("usage", {})
|
|
|
+
|
|
|
+ print("🐑 {}: {}".format(agent_name, output))
|
|
|
+ print()
|
|
|
+ print(" [{:.1f}s | {} tokens | {} steps | run: {}]".format(
|
|
|
+ elapsed, usage.get("total_tokens", 0),
|
|
|
+ usage.get("steps", 0), data.get("run_id", "?")))
|
|
|
+ print()
|
|
|
+
|
|
|
+ conversation.append({"role": agent_name, "content": output[:500]})
|
|
|
+
|
|
|
+
|
|
|
# ============================================================
|
|
|
# Commands: status / health
|
|
|
# ============================================================
|
|
|
@@ -562,11 +685,15 @@ def main():
|
|
|
ag_ver = ag_sub.add_parser("versions"); ag_ver.add_argument("agent_id")
|
|
|
|
|
|
# run
|
|
|
- r = sub.add_parser("run", help="Execute an agent")
|
|
|
+ r = sub.add_parser("run", help="Execute an agent (single shot)")
|
|
|
r.add_argument("agent_id"); r.add_argument("input", nargs="?", default=""); r.add_argument("--input-file", default="")
|
|
|
r.add_argument("--temperature", type=float, default=None); r.add_argument("--max-steps", type=int, default=None)
|
|
|
r.add_argument("--stream", action="store_true")
|
|
|
|
|
|
+ # chat (interactive)
|
|
|
+ ch = sub.add_parser("chat", help="Interactive chat with an agent (via PaaS)")
|
|
|
+ ch.add_argument("target", nargs="?", default="", help="Agent ID (ag_xxx) or name")
|
|
|
+
|
|
|
# status
|
|
|
st = sub.add_parser("status", help="Platform/agent status")
|
|
|
st.add_argument("target", nargs="?", default=""); st.add_argument("--sort", default="last_run")
|
|
|
@@ -614,6 +741,7 @@ def main():
|
|
|
"rollback": cmd_agent_rollback, "versions": cmd_agent_versions
|
|
|
}.get(args.agent_cmd, lambda a: ag.print_help())(args),
|
|
|
"run": lambda: cmd_run(args),
|
|
|
+ "chat": lambda: cmd_chat(args),
|
|
|
"status": lambda: cmd_status(args),
|
|
|
"health": lambda: cmd_health(args),
|
|
|
"runs": lambda: cmd_runs(args),
|
|
|
@@ -632,12 +760,15 @@ def main():
|
|
|
else:
|
|
|
parser.print_help()
|
|
|
print("\nQuick start:")
|
|
|
- print(" agentpaas serve --dev # Start server")
|
|
|
- print(" agentpaas create-tenant --name Org # Get API key")
|
|
|
+ print(" agentpaas serve --dev # 1. Start server")
|
|
|
+ print(" agentpaas create-tenant --name Org # 2. Get API key")
|
|
|
+ print(" agentpaas agent create --name lambda --config agent.yml # 3. Deploy")
|
|
|
+ print(" agentpaas chat lambda # 4. Interactive chat!")
|
|
|
+ print()
|
|
|
+ print("Other commands:")
|
|
|
print(" agentpaas agent list # List agents")
|
|
|
- print(" agentpaas run ag_xxx 'Hello' # Run an agent")
|
|
|
+ print(" agentpaas run ag_xxx 'Hello' # Single-shot run")
|
|
|
print(" agentpaas status # Platform status")
|
|
|
- print(" agentpaas provider list # LLM providers")
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|